All Projects → doodlewind → Freecube

doodlewind / Freecube

Licence: mit
⚛ Solve Rubik's Cube with WebGL in 10KB.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Freecube

Lol Heroes
LOL 3D gallery based on WebGL
Stars: ✭ 82 (-18%)
Mutual labels:  webgl
Medium
Progressive WebGL toolkit for art.
Stars: ✭ 90 (-10%)
Mutual labels:  webgl
Fe Daily Record
📚前端书籍汇集点 + 每日好文推荐 + 公开课学习资料 + 各种大会资料
Stars: ✭ 94 (-6%)
Mutual labels:  webgl
Helixjs
A Javascript 3D game engine.
Stars: ✭ 84 (-16%)
Mutual labels:  webgl
Ternion
A simple starter kit to prototype quickly your ideas with Three.js
Stars: ✭ 89 (-11%)
Mutual labels:  webgl
Nunustudio
Web powered cross-platform 3D, WebXR game engine.
Stars: ✭ 1,302 (+1202%)
Mutual labels:  webgl
Human Gpu
🤖 Hello human, I'm sick to be your GPU!!
Stars: ✭ 76 (-24%)
Mutual labels:  webgl
Glsleditor
Simple WebGL Fragment Shader Editor
Stars: ✭ 1,345 (+1245%)
Mutual labels:  webgl
3dhop
3D Heritage Online Presenter
Stars: ✭ 89 (-11%)
Mutual labels:  webgl
Hlviewer.js
Half-Life in WebGL
Stars: ✭ 93 (-7%)
Mutual labels:  webgl
Cezanne
This is a project showing varied shading algorithms with a simple apple.
Stars: ✭ 85 (-15%)
Mutual labels:  webgl
React Tint
A React component that applies image processing filters to an image using Processing
Stars: ✭ 89 (-11%)
Mutual labels:  webgl
Bgfx
Cross-platform, graphics API agnostic, "Bring Your Own Engine/Framework" style rendering library.
Stars: ✭ 10,252 (+10152%)
Mutual labels:  webgl
Three Forcegraph
Force-directed graph as a ThreeJS 3d object
Stars: ✭ 84 (-16%)
Mutual labels:  webgl
Elm 2d Game
A small rendering engine for creating 2d games with elm, based on WebGL.
Stars: ✭ 94 (-6%)
Mutual labels:  webgl
Sketch Threejs
Interactive sketches made with three.js.
Stars: ✭ 1,227 (+1127%)
Mutual labels:  webgl
Sky Shader
☀️ WebGL sky and sun shader editor
Stars: ✭ 90 (-10%)
Mutual labels:  webgl
Xeokit Bim Viewer
A browser-based BIM viewer, built on the xeokit SDK
Stars: ✭ 99 (-1%)
Mutual labels:  webgl
Black Hole
WebGL simulation of a Schwarzschild black hole
Stars: ✭ 94 (-6%)
Mutual labels:  webgl
Plotly.py
The interactive graphing library for Python (includes Plotly Express) ✨
Stars: ✭ 10,701 (+10601%)
Mutual labels:  webgl

Freecube

⚛ Solve Rubik's Cube with WebGL in 10KB.

banner

Freecube renders and animates Rubik's Cube with raw WebGL, plus a tiny rule-based solver showing how CFOP works.

animate-demo

Usage

npm install freecube
import { Cube, Solver } from 'freecube'

const canvas = document.querySelector('#gl')
const cube = new Cube(canvas)
const solver = new Solver(cube)

cube.render(30, -45) // Render the cube with X and Y rotation.
cube.shuffle(20, true) // Shuffle it with animation.
solver.solve() // Generate solution with CFOP algorithm.

API

Cube

new Cube(canvas: CanvasElement, moves: Moves)

Main class emulating Rubik's Cube, it maintains cube state in this.blocks and optional WebGL instance in this.gl.

  • canvas - DOM canvas element for rendering, can be null for "headless" case.
  • moves - Array of cube moves, .e.g., ['R', 'U', 'F'].

animate

(move: String|Moves, duration: number) => Promise

Animate the cube moves with single or multi move, uses cube.move under the hood. you can set move speed with optional durataion args. The promise returned will be resolved on animation ends.

getBlock

(coord: Coord) => Block

Get block data in the cube. coord shapes as [0, 1, -1] and the block returns in { positions: Array, colors: Array } format. block.positions is the vertex positions of the block, and block.colors represents block colors in [F, B, U, D, R, L] sequence.

move

(move: String|Moves) => Cube

Update cube state with moves passed in, uses cube.rotate under the hood. Just use it as animate without animation. Chain calling like cube.move('U').move('R') is supported.

Only F / B / L / R / U / D and their counter moves can be used for now. "Advanced" turns like M / r / x / R2 are not supported.

rotate

(center: Coord, clockwise: boolean) => Cube

Rotate cube face in 90 degree. center coord is the center block of the face, clockwise for rotate direction.

render

(rX: number, rY: number, moveFace: String, moveAngle: number)

Renders the cube with rX and rY as overall rotation, and moveFace and moveAngle for a cube face rotation.

shuffle

(n: number, animate: false) => Cube|Promise

Shuffles the cube. Returns cube instance if animation not used, and promise on shuffle animation ends.

Solver

Rule-based module solving Rubik's Cube with CFOP algorithm.

solve

() => Array<Moves>

Solve the cube state with all CFOP steps. Returns array of 4 series of moves.

solveCross

() => Moves

Returns the moves to build a cross.

solveF2L

() => Moves

Returns the moves to build first two layers.

solveOLL

() => Moves

Returns the moves to pass OLL.

solvePLL

() => Moves

Returns the moves to pass PLL.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].