emilgoldsmith/elm-speedcubing/11.0.0

NOTE: the latest version is 14.1.0

Cube.Advanced

Definition

type Cube

See Cube

Constructors

Modifiers

Displayers

type alias CubeTheme =
{ up : Rgb255Color
, down : Rgb255Color
, right : Rgb255Color
, left : Rgb255Color
, front : Rgb255Color
, back : Rgb255Color
, plastic : Rgb255Color
, annotations : Rgb255Color
}

The color scheme of the cube, and also color of the "plastic" and the face annotations (U, F, B etc. on the respective sides) text color

type alias Rgb255Color =
( Int, Int, Int )

Just a name for a color tuple for better readability

defaultTheme : CubeTheme

For ease of use here is a pretty standard color scheme for a cube

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

It's exactly the same as Cube.view, except it allows for programmatic screenshotting of the application, and the cost of that is lowered performance. This is due to some WebGL internals which the cube rendering is implemented with

Rendering

type alias Rendering =
{ ufr : CubieRendering
, ufl : CubieRendering
, ubl : CubieRendering
, ubr : CubieRendering
, dfr : CubieRendering
, dfl : CubieRendering
, dbl : CubieRendering
, dbr : CubieRendering
, uf : CubieRendering
, df : CubieRendering
, db : CubieRendering
, ub : CubieRendering
, ur : CubieRendering
, ul : CubieRendering
, dl : CubieRendering
, dr : CubieRendering
, fl : CubieRendering
, fr : CubieRendering
, br : CubieRendering
, bl : CubieRendering
, u : CubieRendering
, d : CubieRendering
, f : CubieRendering
, b : CubieRendering
, l : CubieRendering
, r : CubieRendering
}

This representation of how the cube looks is meant for advanced custom use if you for example want to display the cube differently than this package does, or you need to introspect specific state of the cube for your application.

It is expected that most use cases should be able to fulfill their goals without the use of this, and if you find a use case that you think should be covered by the package itself feel free to submit a Github issue.

Otherwise as mentioned use these rendering methods and types to accomplish all the custom goals you want to!

type alias CubieRendering =
{ u : Color
, d : Color
, f : Color
, b : Color
, l : Color
, r : Color
}

The rendering of one specific cubie (a cubie is one of the pieces of the Rubik's Cube). Note that we describe all sides of all cubies in this model, even the ones that aren't facing outwards.

type Color
= UpColor
| DownColor
| FrontColor
| BackColor
| LeftColor
| RightColor
| PlasticColor

The color of a face of a cubie. The name of the color corresponds to the face of the cube that it belongs to in the initial orientation. So in standard scrambling orientation of the 3x3 cube UpColor is white and RightColor is red. PlasticColor means it is a part of the cubie not facing outwards

render : Cube -> Rendering

Get a Rendering of a cube

Rendering Helpers

type Face
= UpOrDown UOrD
| FrontOrBack FOrB
| LeftOrRight LOrR

Describes all the possible faces of a cubie (a piece on the cube)

type UOrD
= U
| D

A helper type that allows us to make it impossible to represent impossible locations on the cube. By splitting the faces into opposites like we've done with these 3 types we can describe that a corner location is exactly described by one of each of three opposing faces, and not any two faces, and similarly for edges

type LOrR
= L
| R

Same as UOrD

type FOrB
= F
| B

Same as UOrD

A helper constructor for the U face as it's much neater to read than UpOrDown U

A helper constructor for the D face as it's much neater to read than UpOrDown D

A helper constructor for the R face as it's much neater to read than LeftOrRight R

A helper constructor for the L face as it's much neater to read than LeftOrRight L

A helper constructor for the F face as it's much neater to read than FrontOrBack F

A helper constructor for the B face as it's much neater to read than FrontOrBack B

Get the color corresponding to the given face

setColor : Face -> Color -> CubieRendering -> CubieRendering

Set the given color on the given face of the given cubie rendering

faces : Nonempty Face

All possible faces

import List.Nonempty


List.Nonempty.length faces --> 6
type alias CornerLocation =
( UOrD, FOrB, LOrR )

Describes all the possible locations of a corner on a cube

getCorner : CornerLocation -> Cube -> OrientedCorner

Get the corner at the given location of the given cube

setCorner : CornerLocation -> OrientedCorner -> Cube -> Cube

Set the given corner at the given corner location on the given cube

cornerLocations : Nonempty CornerLocation

All possible corner locations

import List.Nonempty


List.Nonempty.length cornerLocations --> 8
= M ( UOrD, FOrB )
| S ( UOrD, LOrR )
| E ( FOrB, LOrR )

Describes all the possible locations of an edge on a cube

getEdge : EdgeLocation -> Cube -> OrientedEdge

Get the edge at the given location on the given cube

setEdge : EdgeLocation -> OrientedEdge -> Cube -> Cube

Set the given edge at the given location of the given cube

All possible edge locations

import List.Nonempty


List.Nonempty.length edgeLocations --> 12

Describes all the possible locations of a center on a cube

Get the center at the given location on the given cube

setCenter : CenterLocation -> Center -> Cube -> Cube

Set the given center at the given location on the given cube

All possible center locations

import List.Nonempty


List.Nonempty.length centerLocations --> 6

Algorithm Helpers

AUF Helpers

{ toDetectFor : Algorithm
, toMatchTo : Algorithm
}
-> Maybe ( AUF, AUF )

General Helpers

Checks whether a cube is only a single U turn away from being solved or not. This is used internally, which is why it sits here under Advanced as it's a pretty particular use case, but can be useful for some AUF logic, hopefully most if not all of your needs should be satisfied by the AUF module though

import Algorithm


Algorithm.fromString "U"
    |> Result.map (\alg -> canBeSolvedBySingleUTurn (applyAlgorithm alg solved))
--> Ok True


Algorithm.fromString "F"
    |> Result.map (\alg -> canBeSolvedBySingleUTurn (applyAlgorithm alg solved))
--> Ok False