Prompt specification
Build or customize the Three.js 3D scene "Move Turn and Place Command Tiles" inside the active workspace.
Engineering Constraints:
1. Runtime & Orbit: Use Three.js r160 with OrbitControls (damping enabled) and ACESFilmicToneMapping.
2. Frame Timing: Drive all motion strictly with clock.getDelta() so animation speed is FPS-independent.
3. Viewport Hygiene: Handle window resize cleanly, cap DPR at Math.min(window.devicePixelRatio, 2), and dispose geometries/materials/renderer on unmount.
Scene Metadata:
Scene: Move Turn and Place Command Tiles
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/move-turn-and-place-command-tiles-x3385
Scene Description Prompt:
Show stylized move, turn, and place command tiles controlling a grid robot, each demonstrated from identical starting states. Three.js from cdnjs; standalone HTML.
Working Three.js Starter (move-turn-and-place-command-tiles-x3385):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Grid Command Lab</title>
<style>
:root {
color-scheme: light;
--ink: #18202a;
--muted: #6f746f;
--paper: #f4f1e9;
--card: #fffdf8;
--line: rgba(24, 32, 42, 0.12);
--move: #079f9a;
--turn: #f1664f;
--place: #e7a82e;
}
* {
box-sizing: border-box;
}
html {
min-width: 320px;
background: var(--paper);
}
body {
margin: 0;
min-height: 100vh;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
background:
radial-gradient(circle at 8% 5%, rgba(7, 159, 154, 0.10), transparent 28rem),
radial-gradient(circle at 94% 10%, rgba(241, 102, 79, 0.10), transparent 28rem),
var(--paper);
}
button {
font: inherit;
}
.app {
width: min(1380px, calc(100% - 40px));
margin: 0 auto;
padding: 42px 0 54px;
}
.masthead {
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 32px;
margin-bottom: 28px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 14px;
color: #626a66;
font-size: 0.72rem;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.eyebrow-mark {
display: inline-grid;
width: 26px;
height: 26px;
grid-template-columns: repeat(2, 1fr);
gap: 3px;
padding: 5px;
border: 1px solid rgba(24, 32, 42, 0.18);
border-radius: 8px;
background: rgba(255, 255, 255, 0.42);
}
.eyebrow-mark i {
border-radius: 2px;
background: var(--ink);
}
.eyebrow-mark i:last-child {
background: var(--move);
}
h1 {
max-width: 760px;
margin: 0;
font-size: clamp(2.35rem, 5vw, 5.35rem);
font-weight: 760;
letter-spacing: -0.065em;
line-height: 0.95;
}
.intro {
max-width: 610px;
margin: 19px 0 0;
color: var(--muted);
font-size: clamp(0.96rem, 1.3vw, 1.08rem);
line-height: 1.65;
}
.header-actions {
display: flex;
flex: 0 0 auto;
gap: 10px;
padding-bottom: 3px;
}
.button {
min-height: 44px;
padding: 0 18px;
border: 1px solid var(--line);
border-radius: 999px;
cursor: pointer;
font-size: 0.78rem;
font-weight: 780;
letter-spacing: 0.035em;
transition:
transform 160ms ease,
background 160ms ease,
border-color 160ms ease;
}
.button:hover {
transform: translateY(-2px);
}
.button:active {
transform: translateY(0);
}
.button.secondary {
color: var(--ink);
background: rgba(255, 255, 255, 0.56);
}
.button.primary {
color: white;
border-color: var(--ink);
background: var(--ink);
box-shadow: 0 8px 22px rgba(24, 32, 42, 0.16);
}
.button.primary span {
margin-left: 8px;
color: #7fe0d8;
}
.shared-state {
display: flex;
align-items: center;
gap: 15px;
margin-bottom: 22px;
padding: 15px 18px;
border: 1px solid var(--line);
border-radius: 18px;
background: rgba(255, 255, 255, 0.48);
backdrop-filter: blur(12px);
}
.shared-icon {
display: grid;
width: 38px;
height: 38px;
flex: 0 0 auto;
place-items: center;
border-radius: 12px;
color: var(--move);
background: rgba(7, 159, 154, 0.10);
}
.shared-icon svg {
width: 21px;
height: 21px;
}
.shared-copy {
display: grid;
gap: 2px;
}
.shared-copy strong {
font-size: 0.84rem;
}
.shared-copy span {
color: var(--muted);
font-size: 0.76rem;
}
.state-flow {
display: flex;
align-items: center;
gap: 10px;
margin-left: auto;
color: #777d78;
font-size: 0.67rem;
font-weight: 800;
letter-spacing: 0.12em;
}
.state-flow i {
display: block;
width: 54px;
height: 1px;
background: rgba(24, 32, 42, 0.24);
position: relative;
}
.state-flow i::after {
content: "";
position: absolute;
right: 0;
top: -3px;
width: 7px;
height: 7px;
border-top: 1px solid rgba(24, 32, 42, 0.4);
border-right: 1px solid rgba(24, 32, 42, 0.4);
transform: rotate(45deg);
}
.demo-grid {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 18px;
}
.demo-card {
--accent: var(--move);
min-width: 0;
overflow: hidden;
border: 1px solid rgba(24, 32, 42, 0.11);
border-radius: 27px;
background: var(--card);
box-shadow:
0 18px 50px rgba(24, 32, 42, 0.07),
0 2px 8px rgba(24, 32, 42, 0.03);
transition:
transform 200ms ease,
box-shadow 200ms ease;
}
.demo-card[data-action="turn"] {
--accent: var(--turn);
}
.demo-card[data-action="place"] {
--accent: var(--place);
}
.demo-card:hover {
transform: translateY(-4px);
box-shadow:
0 24px 58px rgba(24, 32, 42, 0.11),
0 2px 8px rgba(24, 32, 42, 0.03);
}
.card-head {
display: flex;
align-items: center;
gap: 12px;
padding: 18px 20px 12px;
}
.card-index {
display: grid;
width: 39px;
height: 39px;
flex: 0 0 auto;
place-items: center;
border: 1px solid color-mix(in srgb, var(--accent) 34%, transparent);
border-radius: 13px;
color: var(--accent);
background: color-mix(in srgb, var(--accent) 9%, white);
font-size: 0.72rem;
font-weight: 850;
}
.card-title {
min-width: 0;
}
.card-title h2 {
margin: 0;
font-size: 1rem;
letter-spacing: -0.02em;
}
.card-title p {
margin: 3px 0 0;
color: #858984;
font-size: 0.67rem;
font-weight: 750;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.state-pill {
margin-left: auto;
padding: 6px 9px;
border-radius: 999px;
color: #707670;
background: #efeee8;
font-size: 0.61rem;
font-weight: 850;
letter-spacing: 0.1em;
}
.state-pill.running {
color: var(--accent);
background: color-mix(in srgb, var(--accent) 11%, white);
}
.state-pill.done {
color: #267861;
background: #e5f3eb;
}
.stage {
position: relative;
height: clamp(270px, 25vw, 345px);
overflow: hidden;
border-top: 1px solid rgba(24, 32, 42, 0.06);
border-bottom: 1px solid rgba(24, 32, 42, 0.06);
background:
radial-gradient(circle at 50% 40%, rgba(255, 255, 255, 0.92), transparent 58%),
linear-gradient(145deg, #ece9df, #f7f4ec);
}
.stage::before {
content: "";
position: absolute;
inset: 0;
pointer-events: none;
opacity: 0.24;
background-image: radial-gradient(rgba(24, 32, 42, 0.22) 0.7px, transparent 0.7px);
background-size: 14px 14px;
mask-image: linear-gradient(to bottom, transparent, black 32%, transparent);
}
.stage canvas {
position: relative;
z-index: 1;
display: block;
width: 100%;
height: 100%;
outline: none;
}
.scene-badge {
position: absolute;
z-index: 2;
top: 13px;
padding: 6px 9px;
border: 1px solid rgba(24, 32, 42, 0.08);
border-radius: 999px;
color: #747a74;
background: rgba(255, 255, 255, 0.73);
backdrop-filter: blur(7px);
font-size: 0.58rem;
font-weight: 820;
letter-spacing: 0.1em;
pointer-events: none;
}
.scene-badge.origin {
left: 13px;
}
.scene-badge.dimensions {
right: 13px;
}
.tile-wrap {
padding: 18px 18px 13px;
}
.command-tile {
position: relative;
display: block;
width: 100%;
height: 86px;
padding: 0;
border: 0;
color: var(--ink);
background: transparent;
cursor: pointer;
transform: translateY(0);
transition: transform 170ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
.command-tile::before {
content: "";
position: absolute;
inset: 5px 2px 0;
border-radius: 18px;
background: color-mix(in srgb, var(--accent) 28%, #18202a);
transform: translateY(5px);
transition: transform 170ms ease;
}
.tile-face {
position: relative;
z-index: 1;
display: grid;
height: 100%;
grid-template-columns: 52px minmax(0, 1fr) 28px;
align-items: center;
gap: 13px;
padding: 12px 14px;
overflow: hidden;
border: 1px solid color-mix(in srgb, var(--accent) 45%, #d8d5cc);
border-radius: 18px;
background:
linear-gradient(135deg, rgba(255, 255, 255, 0.97), color-mix(in srgb, var(--accent) 7%, white));
box-shadow:
inset 0 1px 0 rgba(255, 255, 255, 0.95),
inset 0 -8px 18px color-mix(in srgb, var(--accent) 5%, transparent);
text-align: left;
}
.tile-face::after {
content: "";
position: absolute;
top: -80%;
left: -35%;
width: 30%;
height: 250%;
background: rgba(255, 255, 255, 0.44);
transform: rotate(18deg);
transition: left 420ms ease;
}
.command-tile:hover {
transform: translateY(-3px);
}
.command-tile:hover::before {
transform: translateY(8px);
}
.command-tile:hover .tile-face::after {
left: 112%;
}
.command-tile:active {
transform: translateY(3px);
}
.command-tile:active::before {
transform: translateY(3px);
}
.command-tile:focus-visible {
outline: 3px solid color-mix(in srgb, var(--accent) 32%, transparent);
outline-offset: 4px;
border-radius: 20px;
}
.tile-icon {
display: grid;
width: 50px;
height: 50px;
place-items: center;
border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
border-radius: 15px;
color: var(--accent);
background: color-mix(in srgb, var(--accent) 10%, white);
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
}
.tile-icon svg {
width: 25px;
height: 25px;
fill: none;
stroke: currentColor;
stroke-width: 1.9;
stroke-linecap: round;
stroke-linejoin: round;
}
.tile-copy {
display: grid;
min-width: 0;
gap: 4px;
}
.tile-copy strong {
font-size: 0.9rem;
font-weight: 900;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.tile-copy small {
overflow: hidden;
color: #777c76;
font-size: 0.72rem;
text-overflow: ellipsis;
white-space: nowrap;
}
.keycap {
display: grid;
width: 27px;
height: 27px;
place-items: center;
border: 1px solid rgba(24, 32, 42, 0.14);
border-bottom-width: 3px;
border-radius: 8px;
color: #777c76;
background: rgba(255, 255, 255, 0.72);
font-size: 0.67rem;
font-weight: 850;
}
.is-running .tile-face {
animation: tile-pulse 650ms ease-in-out infinite alternate;
}
@keyframes tile-pulse {
to {
box-shadow:
inset 0 1px 0 rgba(255, 255, 255, 0.95),
inset 0 -8px 18px color-mix(in srgb, var(--accent) 8%, transparent),
0 0 0 4px color-mix(in srgb, var(--accent) 10%, transparent);
}
}
.result-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
padding: 0 21px 18px;
color: #80847f;
font-size: 0.69rem;
}
.result-row strong {
color: var(--ink);
font-weight: 800;
}
.result-marker {
display: inline-block;
width: 6px;
height: 6px;
margin-right: 7px;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 10%, transparent);
vertical-align: 1px;
}
.hint {
display: flex;
align-items: center;
justify-content: space-between;
gap: 24px;
margin-top: 20px;
padding: 0 4px;
color: #747a74;
font-size: 0.72rem;
line-height: 1.6;
}
.hint strong {
color: var(--ink);
}
.keyboard-hint {
white-space: nowrap;
}
.keyboard-hint kbd {
display: inline-grid;
min-width: 23px;
height: 23px;
place-items: center;
margin: 0 2px;
border: 1px solid rgba(24, 32, 42, 0.18);
border-bottom-width: 2px;
border-radius: 6px;
color: var(--ink);
background: rgba(255, 255, 255, 0.52);
font: inherit;
font-size: 0.64rem;
font-weight: 800;
}
@media (max-width: 980px) {
.masthead {
align-items: flex-start;
flex-direction: column;
}
.demo-grid {
grid-template-columns: 1fr;
}
.stage {
height: 360px;
}
.state-flow {
display: none;
}
}
@media (max-width: 600px) {
.app {
width: min(100% - 24px, 1380px);
padding-top: 26px;
}
h1 {
font-size: clamp(2.55rem, 14vw, 4rem);
}
.header-actions {
width: 100%;
}
.header-actions .button {
flex: 1;
}
.shared-state {
align-items: flex-start;
}
.stage {
height: 320px;
}
.hint {
align-items: flex-start;
flex-direction: column;
gap: 8px;
}
}
@media (prefers-reduced-motion: reduce) {
*,
*::before,
*::after {
scroll-behavior: auto !important;
animation-duration: 1ms !important;
animation-iteration-count: 1 !important;
transition-duration: 1ms !important;
}
}
</style>
</head>
<body>
<main class="app">
<header class="masthead">
<div>
<div class="eyebrow">
<span class="eyebrow-mark" aria-hidden="true"><i></i><i></i><i></i><i></i></span>
Grid command lab / 03
</div>
<h1>Small commands.<br />Clear movement.</h1>
<p class="intro">
Three expressive tiles, one tiny robot, and the same clean origin every time.
Select a command to see exactly how it changes the grid.
</p>
</div>
<div class="header-actions">
<button class="button secondary" id="resetAll" type="button">Reset all</button>
<button class="button primary" id="replayAll" type="button">
Replay all <span aria-hidden="true">↗</span>
</button>
</div>
</header>
<section class="shared-state" aria-label="Shared starting state">
<div class="shared-icon" aria-hidden="true">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8">
<path d="M5 5h14v14H5z" stroke-linejoin="round" />
<path d="M9 5v14M5 9h14M5 15h14" opacity=".55" />
<circle cx="12" cy="12" r="2.2" fill="currentColor" stroke="none" />
</svg>
</div>
<div class="shared-copy">
<strong>Same origin, every time.</strong>
<span>Center cell · facing forward · empty grid · no beacon</span>
</div>
<div class="state-flow" aria-hidden="true">
START <i></i> RESULT
</div>
</section>
<section class="demo-grid" aria-label="Command demonstrations">
<article class="demo-card" data-action="move">
<header class="card-head">
<span class="card-index">01</span>
<div class="card-title">
<h2>Move</h2>
<p>Translation</p>
</div>
<span class="state-pill">READY</span>
</header>
<div class="stage">
<span class="scene-badge origin">START / CENTER</span>
<span class="scene-badge dimensions">GRID 5 × 5</span>
<canvas aria-label="Move command robot demonstration"></canvas>
</div>
<div class="tile-wrap">
<button class="command-tile" type="button" aria-pressed="false" aria-label="Play move command">
<span class="tile-face">
<span class="tile-icon" aria-hidden="true">
<svg viewBox="0 0 24 24">
<path d="M12 20V5" />
<path d="m6.5 10.5 5.5-5.5 5.5 5.5" />
<path d="M7 20h10" opacity=".55" />
</svg>
</span>
<span class="tile-copy">
<strong>Move</strong>
<small>Advance one cell</small>
</span>
<kbd class="keycap">1</kbd>
</span>
</button>
</div>
<footer class="result-row">
<span><i class="result-marker"></i>Center → one cell forward</span>
<strong class="result-copy">Ready</strong>
</footer>
</article>
<article class="demo-card" data-action="turn">
<header class="card-head">
<span class="card-index">02</span>
<div class="card-title">
<h2>Turn</h2>
<p>Rotation</p>
</div>
<span class="state-pill">READY</span>
</header>
<div class="stage">
<span class="scene-badge origin">START / CENTER</span>
<span class="scene-badge dimensions">GRID 5 × 5</span>
<canvas aria-label="Turn command robot demonstration"></canvas>
</div>
<div class="tile-wrap">
<button class="command-tile" type="button" aria-pressed="false" aria-label="Play turn command">
<span class="tile-face">
<span class="tile-icon" aria-hidden="true">
<svg viewBox="0 0 24 24">
<path d="M18.7 8.2A7.2 7.2 0 1 0 19 15" />
<path d="M18.7 4.8v3.6h-3.6" />
<circle cx="12" cy="12" r="1.4" fill="currentColor" stroke="none" opacity=".45" />
</svg>
</span>
<span class="tile-copy">
<strong>Turn</strong>
<small>Pivot 90° right</small>
</span>
<kbd class="keycap">2</kbd>
</span>
</button>
</div>
<footer class="result-row">
<span><i class="result-marker"></i>0° → 90° right</span>
<strong class="result-copy">Ready</strong>
</footer>
</article>
<article class="demo-card" data-action="place">
<header class="card-head">
<span class="card-index">03</span>
<div class="card-title">
<h2>Place</h2>
<p>Object drop</p>
</div>
<span class="state-pill">READY</span>
</header>
<div class="stage">
<span class="scene-badge origin">START / CENTER</span>
<span class="scene-badge dimensions">GRID 5 × 5</span>
<canvas aria-label="Place command robot demonstration"></canvas>
</div>
<div class="tile-wrap">
<button class="command-tile" type="button" aria-pressed="false" aria-label="Play place command">
<span class="tile-face">
<span class="tile-icon" aria-hidden="true">
<svg viewBox="0 0 24 24">
<path d="M12 3v11" />
<path d="m8 10 4 4 4-4" />
<path d="M5 17v3h14v-3" />
<path d="M8 14h8" opacity=".45" />
</svg>
</span>
<span class="tile-copy">
<strong>Place</strong>
<small>Set a beacon ahead</small>
</span>
<kbd class="keycap">3</kbd>
</span>
</button>
</div>
<footer class="result-row">
<span><i class="result-marker"></i>Empty → beacon ahead</span>
<strong class="result-copy">Ready</strong>
</footer>
</article>
</section>
<div class="hint">
<span><strong>Each panel resets before it runs.</strong> Only the selected command changes the robot or grid.</span>
<span class="keyboard-hint">
Quick play <kbd>1</kbd><kbd>2</kbd><kbd>3</kbd>
</span>
</div>
</main>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const CELL = 1.18;
const GRID_SIZE = 5;
const COMMANDS = {
move: {
accent: 0x079f9a,
duration: 900,
running: "MOVING",
result: "Moved one cell forward"
},
turn: {
accent: 0xf1664f,
duration: 720,
running: "TURNING",
result: "Turned 90° right"
},
place: {
accent: 0xe7a82e,
duration: 850,
running: "PLACING",
result: "Beacon placed ahead"
}
};
const easeInOutCubic = (t) =>
t < 0.5 ? 4 * t * t * t : 1 - Math.pow(-2 * t + 2, 3) / 2;
const easeOutCubic = (t) => 1 - Math.pow(1 - t, 3);
class CommandDemo {
constructor(card) {
this.card = card;
this.action = card.dataset.action;
this.config = COMMANDS[this.action];
this.canvas = card.querySelector("canvas");
this.stage = card.querySelector(".stage");
this.tile = card.querySelector(".command-tile");
this.stateEl = card.querySelector(".state-pill");
this.resultEl = card.querySelector(".result-copy");
this.scene = new THREE.Scene();
this.camera = new THREE.OrthographicCamera(-5, 5, 4, -4, 0.1, 100);
this.camera.position.set(7.3, 7.4, 8.8);
this.camera.lookAt(0, 0.35, 0);
this.renderer = new THREE.WebGLRenderer({
canvas: this.canvas,
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
this.renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
this.renderer.setClearColor(0x000000, 0);
this.renderer.shadowMap.enabled = true;
this.renderer.shadowMap.type = THREE.PCFSoftShadowMap;
this.renderer.outputColorSpace = THREE.SRGBColorSpace;
this.renderer.toneMapping = THREE.ACESFilmicToneMapping;
this.renderer.toneMappingExposure = 1.08;
this.active = false;
this.startedAt = 0;
this.addLighting();
this.addGrid();
this.addRobot();
this.addGuides();
this.addBeacon();
this.resizeObserver = new ResizeObserver(() => this.resize());
this.resizeObserver.observe(this.stage);
this.resize();
this.tile.addEventListener("click", () => this.play());
this.restore();
}
addLighting() {
const hemisphere = new THREE.HemisphereLight(0xffffff, 0xa7a292, 1.65);
this.scene.add(hemisphere);
const key = new THREE.DirectionalLight(0xffffff, 3.1);
key.position.set(5.5, 9.5, 7);
key.castShadow = true;
key.shadow.mapSize.set(1024, 1024);
key.shadow.camera.left = -6;
key.shadow.camera.right = 6;
key.shadow.camera.top = 6;
key.shadow.camera.bottom = -6;
key.shadow.camera.near = 0.5;
key.shadow.camera.far = 28;
key.shadow.bias = -0.0004;
this.scene.add(key);
const rim = new THREE.DirectionalLight(0x9edbd7, 1.1);
rim.position.set(-5, 4, -4);
this.scene.add(rim);
const shadowFloor = new THREE.Mesh(
new THREE.PlaneGeometry(18, 18),
new THREE.ShadowMaterial({ color: 0x293039, opacity: 0.11 })
);
shadowFloor.rotation.x = -Math.PI / 2;
shadowFloor.position.y = -0.235;
shadowFloor.receiveShadow = true;
this.scene.add(shadowFloor);
}
addGrid() {
const platform = new THREE.Mesh(
new THREE.BoxGeometry(6.12, 0.2, 6.12),
new THREE.MeshStandardMaterial({
color: 0xd9d4c7,
roughness: 0.92,
metalness: 0
})
);
platform.position.y = -0.13;
platform.receiveShadow = true;
platform.castShadow = true;
this.scene.add(platform);
const geometry = new THREE.BoxGeometry(1.1, 0.075, 1.1);
const half = (GRID_SIZE - 1) / 2;
for (let x = 0; x < GRID_SIZE; x++) {
for (let z = 0; z < GRID_SIZE; z++) {
const isOrigin = x === half && z === half;
const alternating = (x + z) % 2 === 0;
const material = new THREE.MeshStandardMaterial({
color: isOrigin ? 0xfffdf6 : alternating ? 0xe7e3d8 : 0xefebe1,
roughness: 0.86,
metalness: 0.01
});
const cell = new THREE.Mesh(geometry, material);
cell.position.set((x - half) * CELL, -0.005, (z - half) * CELL);
cell.receiveShadow = true;
cell.castShadow = true;
this.scene.add(cell);
}
}
const startRing = new THREE.Mesh(
new THREE.TorusGeometry(0.55, 0.018, 8, 64),
new THREE.MeshBasicMaterial({
color: this.config.accent,
transparent: true,
opacity: 0.32
})
);
startRing.rotation.x = Math.PI / 2;
startRing.position.y = 0.055;
this.scene.add(startRing);
}
addRobot() {
this.robot = new THREE.Group();
this.robot.position.y = 0.04;
this.robot.rotation.order = "YXZ";
const shellMaterial = new THREE.MeshStandardMaterial({
color: 0xf5f0e5,
roughness: 0.48,
metalness: 0.06
});
const darkMaterial = new THREE.MeshStandardMaterial({
color: 0x29313b,
roughness: 0.58,
metalness: 0.22
});
const wheelMaterial = new THREE.MeshStandardMaterial({
color: 0x171c22,
roughness: 0.74,
metalness: 0.08
});
const visorMaterial = new THREE.MeshStandardMaterial({
color: 0x172028,
roughness: 0.25,
metalness: 0.35
});
const eyeMaterial = new THREE.MeshStandardMaterial({
color: this.config.accent,
emissive: this.config.accent,
emissiveIntensity: 1.25,
roughness: 0.3,
metalness: 0.05
});
const lower = new THREE.Mesh(
new THREE.BoxGeometry(0.93, 0.4, 0.78),
darkMaterial
);
lower.position.y = 0.46;
this.robot.add(lower);
const head = new THREE.Mesh(
new THREE.BoxGeometry(1.04, 0.6, 0.86),
shellMaterial
);
head.position.y = 0.96;
this.robot.add(head);
const cap = new THREE.Mesh(
new THREE.BoxGeometry(0.9, 0.075, 0.72),
shellMaterial
);
cap.position.y = 1.29;
this.robot.add(cap);
const visor = new THREE.Mesh(
new THREE.BoxGeometry(0.73, 0.25, 0.035),
visorMaterial
);
visor.position.set(0, 1.01, 0.448);
this.robot.add(visor);
const eye = new THREE.Mesh(
new THREE.BoxGeometry(0.5, 0.065, 0.025),
eyeMaterial
);
eye.position.set(0, 1.025, 0.474);
this.robot.add(eye);
const antenna = new THREE.Mesh(
new THREE.CylinderGeometry(0.027, 0.027, 0.27, 12),
darkMaterial
);
antenna.position.set(0, 1.48, 0);
this.robot.add(antenna);
const antennaTip = new THREE.Mesh(
new THREE.SphereGeometry(0.075, 16, 12),
eyeMaterial
);
antennaTip.position.set(0, 1.64, 0);
this.robot.add(antennaTip);
const wheelGeometry = new THREE.CylinderGeometry(0.18, 0.18, 0.13, 18);
for (const side of [-1, 1]) {
const wheel = new THREE.Mesh(wheelGeometry, wheelMaterial);
wheel.rotation.z = Math.PI / 2;
wheel.position.set(side * 0.52, 0.29, -0.04);
this.robot.add(wheel);
}
this.robot.traverse((object) => {
if (object.isMesh) {
object.castShadow = true;
object.receiveShadow = true;
}
});
this.scene.add(this.robot);
}
addGuides() {
const accent = this.config.accent;
this.moveGuide = new THREE.Group();
const moveMaterial = new THREE.LineDashedMaterial({
color: accent,
dashSize: 0.13,
gapSize: 0.08,
transparent: true,
opacity: 0.8
});
const moveLine = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(0, 0.075, 0.56),
new THREE.Vector3(0, 0.075, CELL - 0.34)
]),
moveMaterial
);
moveLine.computeLineDistances();
this.moveGuide.add(moveLine);
const moveArrow = new THREE.Mesh(
new THREE.ConeGeometry(0.1, 0.24, 3),
new THREE.MeshBasicMaterial({ color: accent })
);
moveArrow.rotation.x = Math.PI / 2;
moveArrow.position.set(0, 0.075, CELL - 0.3);
this.moveGuide.add(moveArrow);
const moveRing = new THREE.Mesh(
new THREE.TorusGeometry(0.43, 0.026, 8, 48),
new THREE.MeshBasicMaterial({
color: accent,
transparent: true,
opacity: 0.65
})
);
moveRing.rotation.x = Math.PI / 2;
moveRing.position.set(0, 0.06, CELL);
this.moveGuide.add(moveRing);
this.moveGuide.visible = false;
this.scene.add(this.moveGuide);
this.turnGuide = new THREE.Group();
const turnPoints = [];
for (let i = 0; i <= 40; i++) {
const angle = (i / 40) * Math.PI * 0.5;
turnPoints.push(
new THREE.Vector3(
Math.sin(angle) * 0.98,
0.08,
Math.cos(angle) * 0.98
)
);
}
const turnLine = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(turnPoints),
new THREE.LineDashedMaterial({
color: accent,
dashSize: 0.12,
gapSize: 0.07,
transparent: true,
opacity: 0.88
})
);
turnLine.computeLineDistances();
this.turnGuide.add(turnLine);
const turnTip = new THREE.Mesh(
new THREE.SphereGeometry(0.065, 14, 10),
new THREE.MeshBasicMaterial({ color: accent })
);
turnTip.position.set(0.98, 0.08, 0);
this.turnGuide.add(turnTip);
this.turnGuide.visible = false;
this.scene.add(this.turnGuide);
this.placeGuide = new THREE.Group();
const placeRing = new THREE.Mesh(
new THREE.TorusGeometry(0.4, 0.027, 8, 48),
new THREE.MeshBasicMaterial({
color: accent,
transparent: true,
opacity: 0.65
})
);
placeRing.rotation.x = Math.PI / 2;
placeRing.position.set(0, 0.06, CELL);
this.placeGuide.add(placeRing);
this.placeGuide.visible = false;
this.scene.add(this.placeGuide);
}
addBeacon() {
this.beacon = new THREE.Group();
this.beacon.position.set(0, 0.045, CELL);
this.beacon.visible = false;
this.beaconDrop = new THREE.Group();
this.beacon.add(this.beaconDrop);
const base = new THREE.Mesh(
new THREE.CylinderGeometry(0.27, 0.31, 0.11, 24),
new THREE.MeshStandardMaterial({
color: 0x273039,
roughness: 0.62,
metalness: 0.15
})
);
base.position.y = 0.08;
this.beaconDrop.add(base);
const beaconMaterial = new THREE.MeshStandardMaterial({
color: 0xffc94f,
emissive: 0x8c5100,
emissiveIntensity: 0.32,
roughness: 0.34,
metalness: 0.06
});
const cube = new THREE.Mesh(
new THREE.BoxGeometry(0.43, 0.43, 0.43),
beaconMaterial
);
cube.position.y = 0.43;
cube.rotation.set(0.08, 0.48, 0.05);
cube.castShadow = true;
this.beaconDrop.add(cube);
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(cube.geometry),
new THREE.LineBasicMaterial({
color: 0x8b5b0d,
transparent: true,
opacity: 0.55
})
);
edges.position.copy(cube.position);
edges.rotation.copy(cube.rotation);
this.beaconDrop.add(edges);
this.beaconLight = new THREE.PointLight(0xffc453, 0.7, 2.1);
this.beaconLight.position.set(0, 0.55, 0);
this.beaconDrop.add(this.beaconLight);
this.scene.add(this.beacon);
}
restore() {
this.active = false;
this.robot.position.set(0, 0.04, 0);
this.robot.rotation.set(0, 0, 0);
this.moveGuide.visible = false;
this.turnGuide.visible = false;
this.placeGuide.visible = false;
this.beacon.visible = false;
this.beaconDrop.position.y = 0;
this.beaconDrop.scale.setScalar(1);
this.card.classList.remove("is-running");
this.tile.classList.remove("is-running");
this.tile.setAttribute("aria-pressed", "false");
this.stateEl.textContent = "READY";
this.stateEl.className = "state-pill";
this.resultEl.textContent = "Ready";
}
play() {
this.restore();
this.active = true;
this.startedAt = performance.now();
this.card.classList.add("is-running");
this.tile.classList.add("is-running");
this.tile.setAttribute("aria-pressed", "true");
this.stateEl.textContent = this.config.running;
this.stateEl.className = "state-pill running";
this.resultEl.textContent = "In progress";
if (this.action === "move") this.moveGuide.visible = true;
if (this.action === "turn") this.turnGuide.visible = true;
if (this.action === "place") {
this.placeGuide.visible = true;
this.beacon.visible = true;
}
}
update(now) {
if (!this.active) return;
const raw = Math.min(1, (now - this.startedAt) / this.config.duration);
const eased = easeInOutCubic(raw);
if (this.action === "move") {
this.robot.position.z = CELL * eased;
this.robot.position.y = 0.04 + Math.sin(raw * Math.PI) * 0.075;
}
if (this.action === "turn") {
this.robot.rotation.y = (Math.PI / 2) * eased;
}
if (this.action === "place") {
const drop = easeOutCubic(raw);
this.beaconDrop.position.y = 1.45 * (1 - drop);
this.beaconDrop.scale.setScalar(0.72 + 0.28 * drop);
this.beaconLight.intensity = 0.7 + Math.sin(raw * Math.PI) * 0.7;
}
if (raw >= 1) {
this.active = false;
this.card.classList.remove("is-running");
this.tile.classList.remove("is-running");
if (this.action === "move") this.robot.position.y = 0.04;
if (this.action === "place") {
this.beaconDrop.position.y = 0;
this.beaconDrop.scale.setScalar(1);
this.beaconLight.intensity = 0.7;
}
this.stateEl.textContent = "DONE";
this.stateEl.className = "state-pill done";
this.resultEl.textContent = this.config.result;
}
}
resize() {
const rect = this.stage.getBoundingClientRect();
const width = Math.max(1, Math.floor(rect.width));
const height = Math.max(1, Math.floor(rect.height));
const aspect = width / height;
const viewHeight = Math.max(7.25, 8.65 / aspect);
this.camera.left = (-viewHeight * aspect) / 2;
this.camera.right = (viewHeight * aspect) / 2;
this.camera.top = viewHeight / 2;
this.camera.bottom = -viewHeight / 2;
this.camera.updateProjectionMatrix();
this.renderer.setSize(width, height, false);
}
render() {
this.renderer.render(this.scene, this.camera);
}
}
const demos = Array.from(
document.querySelectorAll(".demo-card"),
(card) => new CommandDemo(card)
);
document.getElementById("resetAll").addEventListener("click", () => {
demos.forEach((demo) => demo.restore());
});
document.getElementById("replayAll").addEventListener("click", () => {
demos.forEach((demo) => demo.play());
});
window.addEventListener("keydown", (event) => {
if (event.repeat || event.metaKey || event.ctrlKey || event.altKey) return;
const index = Number(event.key) - 1;
if (index >= 0 && index < demos.length) {
demos[index].play();
}
});
function frame(now) {
for (const demo of demos) {
demo.update(now);
demo.render();
}
requestAnimationFrame(frame);
}
requestAnimationFrame(frame);
</script>
</body>
</html>
```