emilgoldsmith/elm-speedcubing/8.0.2

NOTE: the latest version is 14.1.0

Cube

Definition

type alias Cube =

This type represents a 3x3 Rubik's Cube that can be displayed. That means that encoded in the model is also the orientation of the whole cube. This means that a cube with yellow facing upwards is not the same as a cube in the same state with the green face facing upwards.

You can use the helper functions below to manipulate and display the cube. You could for example do something like this:

import Algorithm
import Cube


Cube.solved
    |> Cube.applyAlgorithm
        (
            Algorithm.fromTurnList
                [
                    Algorithm.Turn
                        Algorithm.U
                        Algorithm.Halfway
                        Algorithm.Clockwise
                ]
        )
    |> Cube.viewUFRNoLetters

Constructors

solved : Cube

A solved cube with the initial orientation, so the up face has UpColor etc.

Modifiers

applyAlgorithm : Algorithm -> Cube -> Cube

Apply the given moves of the algorithm to the cube. Reminder that this again depends on the orientation of the cube how the turns will be applied, though problems with this aren't expected to arise often given "normal use".

Displayers

The different supported angles to display a cube from

ufrDisplayAngle : DisplayAngle

The display angle where the U, F, and R faces can be seen

ublDisplayAngle : DisplayAngle

The display angle where the U, B, and L faces can be seen

List (Attribute msg)
-> { pixelSize : Int
, displayAngle : DisplayAngle
, annotateFaces : Bool
}
-> Cube
-> Html msg

Display a 3x3 cube from one of several angles, and with or without the faces annotated with their respective face letters (e.g U R B).

Example Image Of Cube Views

With Animation

Check out the example on Github to see how the different functions interact with each other

List (Attribute msg)
-> { animationState : AnimationState
, toMsg : AnimationMsg -> msg
, pixelSize : Int
, displayAngle : DisplayAngle
, annotateFaces : Bool
}
-> Cube
-> Html msg

Display a cube that can animate turns being applied to it. You can also specify which angle to see it from and whether to annotate the faces just like on view

{ toMsg : AnimationMsg -> msg
, animationDoneMsg : msg
}
-> AnimationState
-> AnimationMsg
-> ( AnimationState, Cmd msg )

The function that can handle the opaque animation message type and output the next animation state and any commands the package needs to have run for it

animateAlgorithm : Algorithm -> AnimationState

The animation state describing the animation of an algorithm. Set this in your model while viewAnimatable is being used and AnimationMsg is being handled and your cube will animate on screen

noAnimation : AnimationState

The animation state describing a static cube with no animated turns applied to it

pauseAnimation : AnimationState -> AnimationState

Pause an animation either to stop it completely or to unpause it later

unpauseAnimation : AnimationState -> AnimationState

Continue a paused animation. This won't have any effect if the animation is not paused

currentTurnAnimating : AnimationState -> Maybe Turn

A helper function that given an animation state will tell you which turn is currently being animated if any

An opaque type that describes the internal state this package uses to manage the animation of turns on a cube

An opaque type describing the internal messages this package uses to manage the animation of a cube

Algorithm Helpers

Some algorithm functionality such as whether two algorithms are equivalent can only be determined in the context of having a cube, so they belong here and not in the Algorithm module.

Check that two algorithms produce the exact same result when applied to a cube. They also have to end at the exact same orientation, so while you may very rarely want this, you are probably looking for algorithmResultAreEquivalentIndependentOfFinalRotation

Checks that two algorithms produce the exact same result, but they are allowed to leave the cube in different orientations / rotations and still be considered equivalent

Changes the algorithm so that it leaves the cube in the same orientation that it started in if it didn't already. It doesn't change what cube state the algorithm leaves the cube in.

If you are wondering why this doesn't live in in the Algorithm module that's a valid question. It is because it makes the most sense in the context of the resulting cube that comes out of an algorithm being applied. If one was to think of it without using the Cube module one would nearly have to reimplement concepts from the Cube module.