Giter Club home page Giter Club logo

siyaofa / jquery.cube.threejs.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from godlikemouse/jquery.cube.threejs.js

0.0 1.0 0.0 36 KB

An implementation of a Rubik's Cube using jQuery and ThreeJS with the ability to read old and new cube notation for executing moves. Supports cube sizes from 2x2 up about 9x9. Supports non-WebGL canvas mode fallback.

Home Page: http://www.collaboradev.com

License: GNU General Public License v3.0

JavaScript 100.00%

jquery.cube.threejs.js's Introduction

jquery.cube.threejs.js

An implementation of a Rubik's Cube using jQuery and ThreeJS with the ability to read old and new cube notation for executing moves. Supports cube sizes from 2x2 up about 9x9.

Compatibility

Browser Compatibility
Chrome Perfect
Firefox Perfect
Opera Perfect
Safari Perfect
IE Perfect - Has not been tested on browsers earlier than IE 11

Usage

(Requires jQuery and ThreeJS) Include the jquery.cube.threejs.js or jquery.cube.threejs.min.js file. Create an HTML container for the cube, implement a script block, initialize the cube plugin and send commands to the plbugin by use of the execute() method or by adding a data-moves parameter.

Quick Start

Create an HTML container for the cube.

<div class="cube"></div>

In JavaScript, initialize the plugin and execute some commands.

var cube = $(".cube").cube();
cube.execute("x (R' U R') D2 (R U' R') D2 (R U R') D2 (R U' R') D2 (R U R') D2 (R U' R') D2 R2 x'");

Options

The following table specifies the options available to be used in conjunction with the plugin.

Name Description
type Specifies the size of the cube to use. (default 3), to create a larger cube increase this value. 4 for 4x4, 5 for 5x5, etc.
camera.x Specifies the camera's x position. (default 50)
camera.y Specifies the camera's y position. (default 50)
camera.z Specifies the camera's z position. (default 100)
size.width Controls the cube width in pixels. (default 60)
size.height Controls the cube height in pixels. (default 60)
color Array sepcifying edge colors. [ right, left, top, bottom, font, back, cube ] (default [0xff0000, 0xff8000, 0xffff00, 0xffffff, 0x0000ff, 0x00ff00, 0x000000])
background Specifies the background color. (default 0x1d1f20)
animation.delay Specifies the animation delay in ms for turns. (default 250)
onTurn Callback function invoked when a turn or move is made. (function (cube, move))
onComplete Callback function invoked when all turns or moves for an execution is complete. (function (cube))
var cube = $(".cube").cube({
	animation: {
		delay: 500 //half a second per turn animation
	},
	colors: [0xff0000,
			 0xff8000,
			 0xffff00,
			 0x000000, //black side instead of white
			 0x0000ff,
			 0x00ff00],
	onTurn: function(cube, move){
		console.info(move, "was made");
	}
});

Moves can also be specified as a data-moves attribute in the HTML tag.

<div class="cube" data-moves="U R U' R'"></div>

API

The following table specifies the API methods available for the cube plugin.

Method Description
execute (moves) Executes a set of moves specified by the moves string. (example: cube.execute("U R U' R'"))
turn (move) Executes a single move specified by the move string. (example: cube.turn("R"))
reset Resets the cube back to its initial state

Living object reference is availble by accessing the following:

var cube = $(".cube").data("_cube");
cube.execute("U R U' R'");

Community

Keep track of development and community news.

License

jquery.cube.js is released under GPL, version 2.0

jquery.cube.threejs.js's People

Contributors

godlikemouse 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.