Skip to content

RubiksCubeEffect

Source: RubiksCubeEffect.h

RubiksCubeEffect

class RubiksCubeEffect
src/light/effects/RubiksCubeEffect.h:30

Inherits: EffectBase

Effect rendering a rotating Rubik's cube on a 3D layout.

RubiksCubeEffect card RubiksCubeEffect controls Author: WildCats08 / @Brandon502 (MoonLight), https://github.com/ewowi/MoonLight/blob/main/src/MoonLight/Nodes/Effects/E_MoonLight.h

The cube scrambles itself, then plays the scramble back one slice at a time. Every voxel takes the color of the nearest face, which is what makes a solid read as a cube.

Prior art: MoonLight's RubiksCube, whose model and move list this reproduces.

Public Attributes

uint8_t turnsPerSecond = 2 : How many slices turn each second.

uint8_t cubeSize = 3 : The cube's order, so 3 is the familiar 3x3x3.

bool randomTurning = false : Turn random slices rather than replaying the scramble backward.

bool usePalette = false : Take the six face colors from the active palette, where a primary-ish one stays distinct.

Public Methods

virtual inline const char * tags() const override : Catalog tags: MoonLight origin, and 3D-native.

virtual inline Dim dimensions() const override : A cube needs all three axes, so this effect is volumetric.

virtual inline void defineControls() override : Publish the turn rate, the cube's order and the two coloring choices.

inline std::array< RGB, 6 > faceColors() const : The six face colors: the classic Rubik's set, or six evenly spaced palette samples.

virtual inline void onControlChanged(const char * name) override : Re-scramble when the cube's order or its turning changes, since neither rebuilds any state.

virtual inline void tick() override : Scramble when asked, then turn one slice per interval and redraw the cube.

More info

The model behind the picture

The cube is a full six-face model, up to 8x8 stickers a face, with the real face, row and column rotations. Each frame it is drawn onto the LED volume by classifying every in-bounds voxel as belonging to whichever outer face it sits nearest, and coloring it from that face's sticker. Turns play at turnsPerSecond, and cubeSize is the order of the cube, 2 through 8 being real cubes and 1 a degenerate single block. With randomTurning the cube tumbles through endless random moves instead of solving a stored scramble.

One difference from the source

MoonLight has no per-cell mapping mask, so every in-bounds voxel counts as mapped. The source's mapping-driven size adjustments are therefore dropped. The projection uses the extent less one instead, floored at 1.