JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q18721F
  • License MIT

Generate rubik's cube scramble images

Package Exports

  • cube-preview

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (cube-preview) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Cube Preview

License: MIT code style: prettier

Contents

Installation

yarn add cube-preview
# or
npm install cube-preview

Usage

Basic Usage

const { CubePreview } = require('cube-preview');

const getPreview = s => new CubePreview().svgString(s);

const state = 'RBLUULUBFRBDBRRBRFFDDFFRLFDBULDDFDLRURLLLDBLUFUBDBUUFR';

getPreview(state);

basic

The state of the cube must be in the form

'UUUUUUUUUR...F...D...L...B...'

The string consists of 54 characters, 9 per face: U means a facelet of the up face color, R means a facelet of the right face color, etc.

The following diagram demonstrates the order of the facelets:

             +------------+
             | U1  U2  U3 |
             |            |
             | U4  U5  U6 |
             |            |
             | U7  U8  U9 |
+------------+------------+------------+------------+
| L1  L2  L3 | F1  F2  F3 | R1  R2  R3 | B1  B2  B3 |
|            |            |            |            |
| L4  L5  L6 | F4  F5  F6 | R4  R5  R6 | B4  B5  B6 |
|            |            |            |            |
| L7  L8  L9 | F7  F8  F9 | R7  R8  R9 | B7  B8  B9 |
+------------+------------+------------+------------+
             | D1  D2  D3 |
             |            |
             | D4  D5  D6 |
             |            |
             | D7  D8  D9 |
             +------------+

Advanced usage

setType

Set the type of puzzle to be drawn. Default is 333.

const get222Preview = (t, s) => new CubePreview().setType(t).svgString(s);

const type = '222';
const state = 'RDRBFRDFULBLDFUFBULURLBD';

get222Preview(type, state);

setType

setCubieSize

Set the size of each cubie in pixels. Default is 20.

const getSmallPreview = (c, s) => new CubePreview().setCubieSize(c).svgString(s);

const cubieSize = 10;
const state = 'RBLUULUBFRBDBRRBRFFDDFFRLFDBULDDFDLRURLLLDBLUFUBDBUUFR';

getSmallPreview(cubieSize, state);

setCubieSize

setSpacing

Set the spacing between each side in pixels. Default is 2.

const getSpacedPreview = (c, s) => new CubePreview().setSpacing(c).svgString(s);

const spacing = 20;
const state = 'RBLUULUBFRBDBRRBRFFDDFFRLFDBULDDFDLRURLLLDBLUFUBDBUUFR';

getSpacedPreview(spacing, state);

setCubieSize

setColorScheme

Set a custom color scheme. You only need to supply the colors you want to change.

const getColoredPreview = (c, s) => new CubePreview().setColorScheme(c).svgString(s);

const colors = {
  U: 'Black',
  R: 'Pink',
  F: '#39FF5A',
  B: 'DeepSkyBlue'
};
const state = 'RBLUULUBFRBDBRRBRFFDDFFRLFDBULDDFDLRURLLLDBLUFUBDBUUFR';

getColoredPreview(colors, state);

setCubieSize

The default color scheme :

defaultColorScheme = {
  U: 'white',
  R: 'red',
  F: 'green',
  D: 'yellow',
  L: 'orange',
  B: 'blue',
};

Status

Works for all NxNxNs.

Only output svg strings.

Contribute

Pull requests are welcome!