Rubik's Cube Simulator using just python
Recommended python version: 3.8
- numpy
- quaternion
- pyglet
Use pip to install these packages (python3 -m pip install <package_name>
)
Clone this repository using following command
git clone https://github.com/VismayVakharia/rubiks-cube-sim
Run main.py
to start the cube simulation
Parameter | Default value | Explanation |
---|---|---|
WIN_W | 640 | Width of the GUI window |
WIN_H | 640 | Height of the GUI window |
CUBE_SIZE | 3 | Rubik's cube size: NxNxN |
COMMANDS | [] |
List of moves (see below) |
PAUSED | False | Whether to start the simulation paused |
RECORDING | False | Whether to record the simulation |
COMMANDS = ["R", "U", "R'", "U'"]
Supported commands:
- 1x1
- Cube rotations:
X Y Z
- Cube rotations:
- 2x2
- Face turns:
F R U B L D
- Cube rotations:
X Y Z
- Face turns:
- 3x3
- Face turns:
F R U B L D
- Dual-layer turns:
f r u b l d
- Slice turns:
M E S
- Cube rotations:
X Y Z
- Face turns:
- Higher NxN
- Face turns:
F R U B L D
- Tier turns:
T<num_layers><face_rotation>
T3R
is three layers deep starting fromR
-layer rotated asR
T1R <=> R
(whereR
could be any face turn)
- Numbered layer turns:
N<layer_number><face_rotation>
N3R
is third layer starting fromR
-layer rotated asR
N1R <=> R
- Numbered range of layers turns:
N<start_layer>-<end_layer><face_rotation>
N2-4R
is second to fourth layers starting fromR
-layer rotated asR
N1-nR <=> TnR | N2-2L <=> N2L
- Cube rotations:
X Y Z
- Face turns:
- Any command
C
(including dual-layer, tier & numbered-layer) can be followed by'
(apostrophe) as inC'
: Same turn asC
, only counter-clockwise2
as inC2
: 180 degC
turn
For detailed explanation on higher order notation, refer this website
Command | Action |
---|---|
F | R | U | B | L | D | Respective face turns |
M | E | S | Respective slice turns |
X | Y | Z | Respective whole-cube rotations |
Space | Pause/Unpause simulation |
Backspace | Reset the cube orientation |
Click & Drag | Rotate the orientation of the cube |
Mouse Scroll | Zoom in/out |
Note: Uppercase letters rotate clockwise and lowercase do counter-clockwise.
If the RECORDING
flag is set True
, animation frames will be saved to frames/
directory.
To convert these frame to:
- gif:
cd frames/ convert -delay 5 -loop 0 `ls -v` output.gif
- mp4:
cd frames/ ffmpeg -framerate 25 -i %d.png -c:v libx264 -profile:v high -crf 20 -pix_fmt yuv420p output.mp4