Giter Club home page Giter Club logo

puzzlejs's Introduction

#Puzzle Js Library

This is a simple javascript library which can generate a puzzle of x rows and y columns of a given image. The image is divided in a number (x * y) of slots, all of the same size.

##License

This software is distributed under the MIT License, read more at https://opensource.org/licenses/MIT

##Requirements

This library is written in vanilla javascript, so you don't need any js framework

##Getting Started

Include the library

<script src="path/to/library/puzzle.js" /></script>

Then in the document

<img id="myImage" src="/path/to/my/image.jpg" />
<div id="here"></div>
<script>
    var p = new pz.Puzzle('myImage', { render_to: 'here', rows: 3, cols: 2 });
</script>

##Usage

var p = new Puzzle(img_id, options);

Options

  • hide_original: whether or not to hide the original image. Default false.
  • render_to: id of the element in which the canvas should be rendered. If not provided is appended to the body. Default null.
  • rows: number of puzzle rows. Default 5.
  • cols: number of puzzle cols. Default 5.
  • margin: number of px of margin between the canvas border and the puzzle. Default 100.
  • snap_offset: number of px of the snap functionality. Default 50.
  • snap_color: hex code of the color of the border when the snap is active. Default '#00ff00'.
  • grid_color: hex code of the color of the puzzle grid. Default '#0000ff'.
  • slot_color: hex code of the color of the slot border. Default '#666'.
  • puzzle_completed_text: text to show when the puzzle is completed after a shuffle, use '%TIME' as a placeholder for the elapsed time. Default 'puzzle completed in %TIME s!'
  • move_after_shuffle: whether or not allow slot dragging only after a shuffle. Default true.

Methods

(void) shuffle()

Shuffles the puzzle slots and activates the timer and "check if completed" feature.

puzzlejs's People

Contributors

abidibo avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.