From e9e1b8da937829aae31e704b165013a56d606a0f Mon Sep 17 00:00:00 2001 From: David Ewing Date: Thu, 3 Dec 2026 06:52:41 -0600 Subject: [PATCH 1/5] CodeX simulator: upright pose, blurred garden, overlay controls - CodeX starts upright, face to the camera (its Z along the room's Y, which the camera looks into); the world's default pose changes with it, so the accelerometer reads +1 g on y. - The garden backdrop is blurred when it is built (sim/tools/showroom-sky.mjs, wrapped at its seam), not in the browser: Three's background blur froze a software-rendered page for about 50 seconds. - Three toggles in the bar show overlays over the view: rotation (a slider and an editable angle to tenths per axis, -180 to 180, from upright, with Upright; the keys keep it in step), ambient light (the sensor's lux, and the scene's lights, reflections and sky scaled to match), and the buttons pad (with a note on the arrow keys and A and B). They replace the bar's light slider and keys and the rotation widget. - The screen-only button has a display icon. - The board's axes start at the accelerometer chip's centre and show only with the rotation overlay. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 9 +++ sim/tools/showroom-sky.mjs | 25 ++++++- src/i18n/en.js | 19 +++-- src/i18n/es.js | 19 +++-- src/sim/sim-device.js | 6 +- src/sim/sim-panel.js | 132 ++++++++++++++++++++++++++++++++--- src/sim/sim.css | 77 ++++++++++++++------ src/sim/view/axes.js | 3 +- src/sim/view/axis-colors.js | 4 ++ src/sim/view/codex-figure.js | 56 ++++++++++----- src/sim/view/view.js | 128 ++++++++++++++++++--------------- src/sim/world/codex.js | 8 ++- tests/sim-ui.mjs | 125 +++++++++++++++++++++++++++------ tests/sim.mjs | 6 ++ 14 files changed, 468 insertions(+), 149 deletions(-) create mode 100644 src/sim/view/axis-colors.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 9987215..54a82e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,15 @@ adds a line under **Unreleased**. ## Unreleased +- The simulated CodeX now stands upright, its screen facing you, and its + accelerometer reads that way (+1 g on y), in front of a softly blurred + garden so the board stands out. Three buttons under the view show or hide + its controls over it: rotation (a slider and an editable angle, to tenths + of a degree, for each of its own axes, with its axes drawn from the + accelerometer chip while it shows), ambient light (which the light sensor + reads, and which visibly lights the scene), and its buttons (the arrow keys + and A and B on the keyboard work too). The screen-only view has a display + icon. - A simulated CodeBot that drives into a wall at 50% power or more no longer stops dead: its wheels slip and keep spinning, a little slower, as a real one's do on a school's floors (below that they stall). Its encoders count diff --git a/sim/tools/showroom-sky.mjs b/sim/tools/showroom-sky.mjs index c48a2f9..21a78e4 100644 --- a/sim/tools/showroom-sky.mjs +++ b/sim/tools/showroom-sky.mjs @@ -1,17 +1,36 @@ // The showroom's sky (CodeX's room, src/sim/view/view.js SHOWROOM_SKY): a // panorama in sim/assets/showroom/sky.jpg (credited in sim/assets/LICENSE). -// Run as a script (npm run sim:assets runs it), this copies it to -// public/sim-assets/env/showroom/sky.jpg, where the site serves it. +// Run as a script (npm run sim:assets runs it), this writes it out of focus +// to public/sim-assets/env/showroom/sky.jpg, where the site serves it, so +// CodeX stands out from the garden's detail. Blurred here, once, rather than +// in the browser: Three's background blur builds its maps on the graphics +// chip, which takes most of a minute where the browser draws without one. +// +// The panorama wraps round, so it is blurred with its far edges joined: a +// strip of each side is laid beside the other before the blur, then cut away. // // node sim/tools/showroom-sky.mjs import fs from 'node:fs' import path from 'node:path' import { fileURLToPath } from 'node:url' +import sharp from 'sharp' const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../..') const SOURCE = path.join(ROOT, 'sim/assets/showroom/sky.jpg') const SERVED = path.join(ROOT, 'public/sim-assets/env/showroom/sky.jpg') +// Served this wide (half the source's: a blurred sky needs no more), and +// blurred by this much of its width (a Gaussian's sigma). +const WIDTH = 2048 +const BLUR = 1 / 300 +const { width, height } = await sharp(SOURCE).metadata() +const sigma = width * BLUR +const pad = Math.ceil(sigma * 4) +const wrapped = await sharp(SOURCE).extend({ left: pad, right: pad, extendWith: 'repeat' }).blur(sigma).toBuffer() fs.mkdirSync(path.dirname(SERVED), { recursive: true }) -fs.copyFileSync(SOURCE, SERVED) +await sharp(wrapped) + .extract({ left: pad, top: 0, width, height }) + .resize(WIDTH, WIDTH / 2) + .jpeg({ quality: 82, mozjpeg: true }) + .toFile(SERVED) console.log('showroom sky', fs.statSync(SERVED).size) diff --git a/src/i18n/en.js b/src/i18n/en.js index 8d409c5..1f77c10 100644 --- a/src/i18n/en.js +++ b/src/i18n/en.js @@ -691,14 +691,17 @@ You just told a machine what to do, and it listened. Keep going!`, 'sim.stoppedTitle': 'The simulator stopped', 'sim.stoppedDetail': 'Reload the page to start it again.', 'sim.problemTitle': 'The simulator hit a problem', - 'sim.keysCodex': 'Arrow keys press its direction pad, A and B its buttons; Shift and the arrow keys turn it about its own X and Y axes, Shift with Page Up and Page Down about its Z axis, Home lays it flat again; plus and minus zoom, F shows its screen alone. The Rotate buttons turn it too.', + 'sim.keysCodex': 'Arrow keys press its direction pad, A and B its buttons; Shift and the arrow keys turn it about its own X and Y axes, Shift with Page Up and Page Down about its Z axis, Home stands it upright again; plus and minus zoom, F shows its screen alone. The rotation sliders turn it too.', 'sim.rotate.label': 'Rotate CodeX about its own axes', - 'sim.rotate.title': 'Rotate', - 'sim.rotate.back': 'Turn back about {axis}', - 'sim.rotate.on': 'Turn about {axis}', + 'sim.rotate.title': 'Rotation', + 'sim.rotate.slider': 'Turn about {axis}', + 'sim.rotate.degrees': 'Degrees about {axis}', + 'sim.light.title': 'Ambient light', + 'sim.light.value': '{lux} lux', + 'sim.pad.note': 'Your keyboard works too: the arrow keys and A and B, once you click the CodeX view.', 'sim.worldAxes': 'World axes', 'sim.lcdLabel': 'The CodeX screen', - 'sim.rotate.reset': 'Reset', + 'sim.rotate.reset': 'Upright', 'sim.keys3d': 'Arrow keys turn or move the camera, plus and minus zoom.', 'sim.viewLabel': 'Simulated {device}. {keys}', 'sim.ready': 'Simulator ready. Press Run!', @@ -731,8 +734,10 @@ You just told a machine what to do, and it listened. Keep going!`, 'simPanel.courseTitle': 'A line course of black tape on the floor', 'simPanel.course': 'Line course', 'simPanel.noCourse': 'No course', - 'simPanel.lightTitle': 'Light on the sensor (lux)', 'simPanel.light': 'Light on the sensor, lux', + 'simPanel.rotateShow': 'Rotation: turn CodeX about its own axes', + 'simPanel.lightShow': 'Ambient light: how bright the room is', + 'simPanel.buttonsShow': "CodeX's buttons", 'simPanel.speed': 'Simulation speed', 'simPanel.speedValue': '{speed}×', 'simPanel.buttons': "The board's buttons (hold Space or Enter)", @@ -791,7 +796,7 @@ You just told a machine what to do, and it listened. Keep going!`, 'codex.down': 'Down', 'codex.buttonA': 'Button A', 'codex.buttonB': 'Button B', - 'codex.fullTitle': 'Screen only: the CodeX screen filling the view (F, or Esc to go back)', + 'codex.fullTitle': 'Display: the CodeX screen alone, filling the view (F, or Esc to go back)', // The simulated board in words, for a screen reader 'compass.east': 'east', diff --git a/src/i18n/es.js b/src/i18n/es.js index 8234bcd..53f86d3 100644 --- a/src/i18n/es.js +++ b/src/i18n/es.js @@ -668,14 +668,17 @@ Le acabas de decir a una máquina qué hacer, y te hizo caso. ¡Sigue así!`, 'sim.stoppedTitle': 'El simulador se detuvo', 'sim.stoppedDetail': 'Vuelve a cargar la página para iniciarlo otra vez.', 'sim.problemTitle': 'El simulador tuvo un problema', - 'sim.keysCodex': 'Las flechas presionan su control de dirección, A y B sus botones; Mayús y las flechas lo giran sobre sus propios ejes X e Y, Mayús con Re Pág y Av Pág sobre su eje Z, Inicio lo deja plano otra vez; más y menos hacen zoom, F muestra solo su pantalla. Los botones de Girar también lo giran.', + 'sim.keysCodex': 'Las flechas presionan su control de dirección, A y B sus botones; Mayús y las flechas lo giran sobre sus propios ejes X e Y, Mayús con Re Pág y Av Pág sobre su eje Z, Inicio la vuelve a poner de pie; más y menos hacen zoom, F muestra solo su pantalla. Los controles deslizantes de rotación también la giran.', 'sim.rotate.label': 'Girar la CodeX sobre sus propios ejes', - 'sim.rotate.title': 'Girar', - 'sim.rotate.back': 'Girar hacia atrás sobre {axis}', - 'sim.rotate.on': 'Girar sobre {axis}', + 'sim.rotate.title': 'Rotación', + 'sim.rotate.slider': 'Girar sobre {axis}', + 'sim.rotate.degrees': 'Grados sobre {axis}', + 'sim.light.title': 'Luz ambiente', + 'sim.light.value': '{lux} lux', + 'sim.pad.note': 'Tu teclado también funciona: las flechas y A y B, después de hacer clic en la vista de la CodeX.', 'sim.worldAxes': 'Ejes del mundo', 'sim.lcdLabel': 'La pantalla de la CodeX', - 'sim.rotate.reset': 'Restablecer', + 'sim.rotate.reset': 'De pie', 'sim.keys3d': 'Las flechas giran o mueven la cámara, más y menos hacen zoom.', 'sim.viewLabel': '{device} simulado. {keys}', 'sim.ready': 'Simulador listo. ¡Presiona Ejecutar!', @@ -708,8 +711,10 @@ Le acabas de decir a una máquina qué hacer, y te hizo caso. ¡Sigue así!`, 'simPanel.courseTitle': 'Un recorrido de cinta negra en el piso', 'simPanel.course': 'Recorrido', 'simPanel.noCourse': 'Sin recorrido', - 'simPanel.lightTitle': 'Luz sobre el sensor (lux)', 'simPanel.light': 'Luz sobre el sensor, lux', + 'simPanel.rotateShow': 'Rotación: girar la CodeX sobre sus propios ejes', + 'simPanel.lightShow': 'Luz ambiente: qué tan iluminada está la sala', + 'simPanel.buttonsShow': 'Los botones de la CodeX', 'simPanel.speed': 'Velocidad de simulación', 'simPanel.speedValue': '{speed}×', 'simPanel.buttons': 'Los botones de la placa (mantén presionado Espacio o Enter)', @@ -768,7 +773,7 @@ Le acabas de decir a una máquina qué hacer, y te hizo caso. ¡Sigue así!`, 'codex.down': 'Abajo', 'codex.buttonA': 'Botón A', 'codex.buttonB': 'Botón B', - 'codex.fullTitle': 'Solo la pantalla: la pantalla de la CodeX llenando la vista (F, o Esc para volver)', + 'codex.fullTitle': 'Pantalla: solo la pantalla de la CodeX, llenando la vista (F, o Esc para volver)', // La placa simulada en palabras, para un lector de pantalla 'compass.east': 'este', diff --git a/src/sim/sim-device.js b/src/sim/sim-device.js index d0ad076..4997856 100644 --- a/src/sim/sim-device.js +++ b/src/sim/sim-device.js @@ -218,7 +218,11 @@ export class SimDevice extends EventTarget { return this._resetting } orient(q) { this._post({ t: 'input', what: 'orient', q }) } - setLight(lux) { this._post({ t: 'input', what: 'light', lux }) } + // The light on CodeX's sensor, in lux: the program reads it, and the view lights the scene to match. + setLight(lux) { + this._post({ t: 'input', what: 'light', lux }) + this.view?.setLight?.(lux) + } reset() { this._post({ t: 'reset' }) } // Lay a line course (an id from world/courses.js, or null for none); the // robot starts again on it. diff --git a/src/sim/sim-panel.js b/src/sim/sim-panel.js index 3ac0c6f..802b4e8 100644 --- a/src/sim/sim-panel.js +++ b/src/sim/sim-panel.js @@ -6,6 +6,7 @@ import { COURSES } from './world/courses.js' import { KINDS, ROOMS, CAMERA_MODES } from './kinds.js' import { holdButton } from './hold-button.js' import { SettingsPanel } from './settings-panel.js' +import { AXIS_COLORS } from './view/axis-colors.js' import { t, tHtml } from '../i18n/index.js' const SPEEDS = [0.5, 1, 2, 4] @@ -18,6 +19,19 @@ const icon = (d) => ` `
+ + + +
` host.innerHTML = `
-
+
+ +