本文へ移動

Kyuubuキューブ

CSS 3Dのキューブをタッチ、キー、回転記号で回します。シードでスクランブルを再現し、名前付きの手順で解き方を追えます。

「キューブ」は、英語のcubeを表す日本語の表記です。 名前について(英語)

目次

リファレンス · キューブのエンジンと表示

CubeViewクラス

リファレンスの説明と例は英語です。見出しと目次は日本語です。

A cube on the screen. new CubeView(element, { size: 3 }) draws it in the element, which it fills, so the element needs a size; destroy() takes it away again with every listener.

インポート

import { CubeView } from "@johnmorrisdotca/kyuubu";

定義

class CubeView
new CubeView(host: HTMLElement, options: CubeViewOptions): CubeView

引数

名前型説明
hostHTMLElement

The DOM host with a size and position.

optionsCubeViewOptions

View or replay options.

メンバー

名前型説明
statestring

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

sizenumber

The cube's side.

setTheme(theme: CubeTheme): void

Change how the cube looks, at once and without redrawing it: any of its colours, its plastic, and the shape of its stickers. What is left out of theme stays as it is. To go back to the CSS custom properties and the standard colours, pass CUBE_THEMES.standard, or make the cube again.

setLocale(locale: KyuubuLanguage): void

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

setScale(scale?: CubeScale, width?: number): void

Draw the cube at a scale, or at a width in pixels (which wins), or with neither, back to filling the box it is in. The box keeps one steady square, never wider than its container, so nothing round it moves when the cube does. The cube's own interactive is not touched.

setInteractive(interactive: boolean): void

Whether a person can turn it now.

setState(state: string, size?: number): void

Put the stickers as given, at once, dropping any turn still to come.

turn(move: CubeMove, { report, animate }?: { report?: boolean; animate?: boolean; }): void

Turn a layer, animated after any turns already on their way. Told to onTurn only when report says so.

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

Several layers about one axis turned together, the same way and as far, as one movement: a wide turn (Rw is the right face and the layer behind it). ms, when given, is how long the whole movement takes, whatever turnMs says, so a replay can keep a solve's own pace; a device that asks for reduced motion still gets none. Never told to onTurn. Moves that do not share an axis and a distance are turned one after another.

scramble(moves: readonly CubeMove[], { animate }?: { animate?: boolean; }): void

Scramble the cube with these turns, from the cube as it is. Turned quickly, the way a hand scrambles it: the last ten are shown, each in under a tenth of a second, and every one before them is made at once, so a scramble of a hundred turns on a 7×7 is over in a second and not a blur that shows nothing. With animate: false, or animateScramble: false when the cube was made, nothing is shown turning. Never told to onTurn.

busyboolean

Whether a turn asked for is still on its way.

redraw(): void

The cube taken out of the page and put straight back, so that the browser makes its layers again. Nothing about it changes.

setTurnMs(ms: number): void

How long a quarter turn made by a key, by notation or from code takes, in milliseconds, from now on.

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

Look at the cube from another way round, in degrees.

on(type: "turn", listener: CubeViewEvents["turn"]): () => void (type: "look", listener: CubeViewEvents["look"]): () => void

Listen for what the cube tells onTurn and onLook, beside them, as many listeners as are wanted: "turn" for every turn a person makes, "look" whenever the view turns. Returns what stops listening.

showHint(moves: CubeMove | readonly CubeMove[] | null): void

Show on the cube how to make a turn: the layer that turns is lit and the rest dimmed, and an arrow lies across the stickers the way to drag them, worked out afresh whenever the cube is looked at from somewhere else. The arrow is the drag's own rules run backwards, so a drag along it from the sticker at its tail is that turn. Several layers about one axis turned as far (a wide turn) are lit as one slab with one arrow; each is dragged on its own. A turn of the whole cube lights nothing: no drag on a sticker makes it. null takes the hint away. Nothing about the cube changes.

hintDragHint | null

What the hint shows from where the cube is looked at now: the layers lit, the sticker to take hold of and the way to drag it; null with no hint, or for a turn of the whole cube.

resetLook(): void

Back to the way it was first seen.

looking{ yaw: number; pitch: number; }

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

destroy(): void

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

hostHTMLElement

The element the cube was made in.

例

import { CubeView } from "@johnmorrisdotca/kyuubu";

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

ソースを見るGitHub で編集@johnmorrisdotca/kyuubu 1.14.1 のソースから作成しました。

この日本語は、まだ日本語を母語とする方の確認を受けていません。訂正を歓迎します。