Skip to the content

Kyuubuキューブ

Turn CSS 3D cubes by touch, keys or notation, reproduce a scramble from a seed, and follow a solve one named step at a time.

Kyuubu (キューブ) is the Japanese spelling of cube. About the name

Contents

Reference · Cuboid drawing

CuboidViewclass

A cuboid on the screen. new CuboidView(element, { dims: [2, 3, 3] }) draws it in the element, which it fills, so the element needs a size; destroy() takes it away again with every listener. A turn the puzzle cannot make throws a RangeError, as turnCuboid does.

Import it

import { CuboidView } from "@johnmorrisdotca/kyuubu/cuboid/draw";

Definition

class CuboidView
new CuboidView(host: HTMLElement, options: CuboidViewOptions): CuboidView

Parameters

NameTypeDescription
hostHTMLElement

The DOM host with a size and position.

optionsCuboidViewOptions

View or replay options.

Members

NameTypeDescription
statestring

The stickers as they will be once every turn asked for has finished.

dimsCuboidDims

The puzzle's width, height and depth.

busyboolean

Whether a turn is on its way or a layer is held.

looking{ yaw: number; pitch: number; }

The way the puzzle is looked at now, in degrees.

setTheme(theme: CubeTheme): void

Change how the puzzle looks, at once and without redrawing it. What is left out of theme stays as it is.

setLocale(locale: KyuubuLanguage): void

The language of the puzzle's accessible name. A label given when it was made is left as it is.

setInteractive(interactive: boolean): void

Whether a person can turn it now.

setTurnMs(ms: number): void

How long a quarter turn takes, in milliseconds, from now on.

setState(state: string, dims?: CuboidDims): void

Put the stickers as given, at once, dropping any turn still to come. Another dims draws another puzzle.

turn(move: CuboidMove, { report, animate, ms }?: { report?: boolean; animate?: boolean; ms?: number; }): void

Turn a layer, animated after any turns already on their way. Told to onTurn only when report says so. A turn the puzzle cannot make throws a RangeError.

turnTogether(moves: readonly CuboidMove[], options?: { animate?: boolean; ms?: number; }): void

The same as turn, one move: for a replay, which plays steps made of several layers on a cube.

on<K extends keyof CuboidViewEvents>(type: K, listener: CuboidViewEvents[K]): () => void

Listen for a turn a person made (turn) or the view turned (look). Returns the call that stops listening.

setLook(yaw: number, pitch: number): void

Turn the view to look at the puzzle from here. The pitch stays between −90 and 90 degrees.

resetLook(): void

Back to the way the puzzle was first looked at.

redraw(): void

Build the 3D layers again, as a browser that let go of them needs.

destroy(): void

Take the puzzle off the page, with every listener it added.

hostHTMLElement

The element the puzzle was made in.

Examples

import { CuboidView } from "@johnmorrisdotca/kyuubu/cuboid/draw";

const host = document.createElement("div");
host.style.cssText = "width:300px;height:300px;position:relative";
document.body.append(host);
const cube = new CuboidView(host, { dims: [2, 3, 3], interactive: true });
console.log(cube.state);
// Call cube.destroy() when the host is removed.

View sourceEdit on GitHubMade from the source of @johnmorrisdotca/kyuubu 1.14.1.