Skip to content

VismayVakharia/rubiks-cube-sim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rubiks-cube-sim

Rubik's Cube Simulator using just python

Cube 3x3

Installation

Dependencies

Recommended python version: 3.8

  • numpy
  • quaternion
  • pyglet

Use pip to install these packages (python3 -m pip install <package_name>)

Setup

Clone this repository using following command
git clone https://github.com/VismayVakharia/rubiks-cube-sim

Usage

Run main.py to start the cube simulation

Parameters

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 Example

COMMANDS = ["R", "U", "R'", "U'"]

Supported commands:

  • 1x1
    • Cube rotations: X Y Z
  • 2x2
    • Face turns: F R U B L D
    • Cube rotations: X Y Z
  • 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
  • Higher NxN
    • Face turns: F R U B L D
    • Tier turns: T<num_layers><face_rotation>
      • T3R is three layers deep starting from R-layer rotated as R
      • T1R <=> R (where R could be any face turn)
    • Numbered layer turns: N<layer_number><face_rotation>
      • N3R is third layer starting from R-layer rotated as R
      • N1R <=> R
    • Numbered range of layers turns: N<start_layer>-<end_layer><face_rotation>
      • N2-4R is second to fourth layers starting from R-layer rotated as R
      • N1-nR <=> TnR | N2-2L <=> N2L
    • Cube rotations: X Y Z
  • Any command C (including dual-layer, tier & numbered-layer) can be followed by
    • ' (apostrophe) as in C': Same turn as C, only counter-clockwise
    • 2 as in C2: 180 deg C turn

For detailed explanation on higher order notation, refer this website

GUI Control

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.

Recording

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

Releases

No releases published

Packages

No packages published

Languages