realistic rubik cube - Free Download Create A Realistic Self-solving Rubik's Cube With Three.js

Free Download Create A Realistic Self-solving Rubik’s Cube With Three.js

Posted on

This time I will share jQuery Plugin and tutorial about Create A Realistic Self-solving Rubik’s Cube With Three.js, hope it will help you in programming stack.

realistic rubik cube - Free Download Create A Realistic Self-solving Rubik's Cube With Three.js
File Size: 25.3 KB
Views Total: 758
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   

A funny jQuery plugin that lets you render a realistic, self-solving Rubik’s Cube (up to 9×9) on an HTML5 canvas element using the Three.js JavaScript 3D library.

The jquery.cube.threejs.js plugin is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

How to use it:

1. Include the latest version of jQuery and Three.js libraries from CDN.

1 <script src="/path/to/cdn/jquery.min.js"></script>
2 <script src="/path/to/cdn/three.min.js"></script>

2. Create placeholder element and define a set of moves to solve the Rubik’s Cube as follows:

1 <div class="cube"
2      data-moves="(U R U' R') (U R U' R') (U R U' R') (U R U' R') (U R U' R') (U R U' R')">
3 </div>

3. Download and load the jquery.cube.threejs.min.js after jQuery.

1 <script src="jquery.cube.threejs.min.js"></script>

4. Render a basic (3×3) self-solving Rubik’s Cube on the webpage.

1 $(function(){
2   $(".cube").cube();
3 });

5. You’re also allowed to solve the Rubik’s Cube using the execute method when needed.

1 <div class="cube">
2 </div>
1 $(function(){
2   const myCube = $(".cube").cube();
3   myCube.execute("(U R U' R') (U R U' R') (U R U' R') (U R U' R') (U R U' R') (U R U' R')");
4 });

6. Determine the cube type. Defaults to 3 (3×3).

1 $(".cube").cube({
2   type: 2 // up to 9
3 });

7. Determine the delay between each turn. Defaults to 250ms.

1 $(".cube").cube({
2   animation: {
3     delay: 500
4   }
5 });

8. Customize the cube & background colors.

01 $(".cube").cube({
02   color: [
03     0xff0000, //right
04     0xff8000, //left
05     0xffff00, //top
06     0xffffff, //bottom
07     0x0000ff, //front
08     0x00ff00, //back
09     0x000000 //cube color
10   ],
11   background: 0x1D1F20
12 });

9. Customize the cube size.

1 $(".cube").cube({
2   size: {
3     width: 60,
4     height: 60
5   }
6 });

10. Specify the camera position.

1 $(".cube").cube({
2   camera: {
3     x: 50,
4     y: 50,
5     z: 100
6   }
7 });

11. Callback functions.

1 $(".cube").cube({
2   onTurn: function(cube, move){
3     console.info(move, "was made");
4   },
5   onComplete: function(cube){
6     console.info("Finished");
7   }
8 });

12. More API methods.

1 // Executes a single move
2 myCube.turn(move);
3  
4 // Resets the cube
5 myCube.reset();

This awesome jQuery plugin is developed by godlikemouse. For more Advanced Usages, please check the demo page or visit the official website.