Prompt specification
Build or customize the Three.js 3D scene "Near Star and Two Observer Positions" 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: Near Star and Two Observer Positions
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/near-star-and-two-observer-positions-x3833
Scene Description Prompt:
I'd like to see this as a stylized Three.js scene: near star and two observer positions. Place a nearby star marker before a distant background grid with two observer points. Show the sight lines and distinguish apparent angular shift from actual stellar motion. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (near-star-and-two-observer-positions-x3833):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Parallax — Two-Observer Angular Shift</title>
<style>
:root {
color-scheme: dark;
--bg: #050816;
--panel: rgba(10, 17, 36, 0.78);
--border: rgba(145, 184, 222, 0.18);
--text: #edf5ff;
--muted: #8fa4bd;
--sight: #ffe39a;
--initial: #8fa0b7;
--actual: #39e6c3;
--angle-a: #ff639f;
--angle-b: #a58aff;
--grid: #315d79;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--text);
}
body {
background:
radial-gradient(circle at 50% 42%, rgba(29, 58, 92, 0.2), transparent 38%),
radial-gradient(circle at 15% 85%, rgba(70, 37, 100, 0.16), transparent 32%),
#050816;
}
button,
input {
font: inherit;
}
#stage,
#labels {
position: fixed;
inset: 0;
}
#stage {
z-index: 0;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#stage canvas:active {
cursor: grabbing;
}
#labels {
z-index: 2;
pointer-events: none;
overflow: hidden;
}
.ui {
position: fixed;
z-index: 5;
}
.intro {
top: 22px;
left: 24px;
width: min(520px, calc(100vw - 48px));
pointer-events: none;
text-shadow: 0 2px 18px rgba(0, 0, 0, 0.7);
}
.eyebrow {
display: inline-flex;
align-items: center;
gap: 8px;
margin-bottom: 10px;
color: #9dc8df;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.eyebrow::before {
width: 22px;
height: 1px;
content: "";
background: #59b4d4;
box-shadow: 0 0 10px #59b4d4;
}
h1 {
margin: 0;
font-size: clamp(30px, 4vw, 52px);
font-weight: 620;
line-height: 0.98;
letter-spacing: -0.045em;
}
.intro p {
max-width: 490px;
margin: 14px 0 0;
color: #a9bad0;
font-size: 13px;
line-height: 1.55;
}
.intro p strong {
color: var(--actual);
font-weight: 650;
}
.legend {
top: 22px;
right: 24px;
width: 235px;
padding: 14px;
border: 1px solid var(--border);
border-radius: 15px;
background: var(--panel);
box-shadow: 0 18px 60px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(16px);
}
.legend-title {
margin-bottom: 10px;
color: #dce9f6;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.legend-row {
display: flex;
align-items: center;
gap: 9px;
min-height: 25px;
color: #b8c7d9;
font-size: 11px;
}
.legend-row small {
display: block;
margin-top: 1px;
color: #71869f;
font-size: 9px;
}
.swatch {
flex: 0 0 auto;
width: 24px;
height: 2px;
border-radius: 2px;
background: currentColor;
box-shadow: 0 0 8px currentColor;
}
.swatch.dashed {
height: 0;
border-top: 1px dashed currentColor;
background: none;
box-shadow: none;
}
.swatch.arc {
width: 15px;
height: 15px;
border: 2px solid currentColor;
border-right-color: transparent;
border-radius: 50%;
background: none;
box-shadow: none;
}
.swatch.angle-pair {
position: relative;
width: 15px;
height: 15px;
border: 2px solid var(--angle-a);
border-right-color: var(--angle-b);
border-bottom-color: var(--angle-b);
border-radius: 50%;
background: none;
box-shadow: none;
}
.legend-note {
margin-top: 10px;
padding-top: 10px;
border-top: 1px solid rgba(145, 184, 222, 0.12);
color: #71869f;
font-size: 9px;
line-height: 1.45;
}
.dock {
right: 50%;
bottom: 20px;
width: min(940px, calc(100vw - 36px));
padding: 13px;
transform: translateX(50%);
border: 1px solid var(--border);
border-radius: 18px;
background: rgba(8, 15, 32, 0.86);
box-shadow: 0 24px 80px rgba(0, 0, 0, 0.42);
backdrop-filter: blur(20px);
}
.control-row {
display: flex;
align-items: center;
gap: 10px;
}
.transport {
display: flex;
flex: 0 0 auto;
gap: 5px;
}
.control-button {
display: grid;
width: 34px;
height: 34px;
padding: 0;
place-items: center;
border: 1px solid rgba(145, 184, 222, 0.18);
border-radius: 9px;
background: rgba(111, 151, 189, 0.08);
color: #c8d8e8;
cursor: pointer;
transition: border-color 150ms, background 150ms, transform 150ms;
}
.control-button:hover {
border-color: rgba(145, 184, 222, 0.38);
background: rgba(111, 151, 189, 0.16);
transform: translateY(-1px);
}
.control-button.primary {
border-color: rgba(57, 230, 195, 0.38);
background: rgba(57, 230, 195, 0.13);
color: #72f1d8;
}
.control-button.text {
width: auto;
padding: 0 12px;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.scrubber {
display: grid;
flex: 1 1 auto;
grid-template-columns: auto minmax(100px, 1fr) 42px;
align-items: center;
gap: 10px;
min-width: 160px;
}
.scrubber label {
color: #9eb0c5;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
white-space: nowrap;
}
input[type="range"] {
width: 100%;
height: 4px;
margin: 0;
border-radius: 10px;
outline: none;
appearance: none;
background: linear-gradient(
90deg,
rgba(57, 230, 195, 0.8),
rgba(98, 133, 171, 0.22)
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 15px;
height: 15px;
border: 3px solid #07101f;
border-radius: 50%;
appearance: none;
background: #63ecd0;
box-shadow: 0 0 0 1px rgba(57, 230, 195, 0.5), 0 0 14px rgba(57, 230, 195, 0.45);
}
input[type="range"]::-moz-range-thumb {
width: 11px;
height: 11px;
border: 3px solid #07101f;
border-radius: 50%;
background: #63ecd0;
box-shadow: 0 0 0 1px rgba(57, 230, 195, 0.5), 0 0 14px rgba(57, 230, 195, 0.45);
}
output {
color: #d9e8f7;
font-variant-numeric: tabular-nums;
font-size: 11px;
text-align: right;
}
.toggles {
display: flex;
flex: 0 0 auto;
gap: 8px;
margin-left: 4px;
}
.toggle {
display: inline-flex;
align-items: center;
gap: 5px;
color: #8398af;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.035em;
white-space: nowrap;
cursor: pointer;
user-select: none;
}
.toggle input {
width: 12px;
height: 12px;
margin: 0;
accent-color: #58ddc4;
cursor: pointer;
}
.metric-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 8px;
margin-top: 11px;
}
.metric {
position: relative;
overflow: hidden;
padding: 10px 12px;
border: 1px solid rgba(145, 184, 222, 0.12);
border-radius: 11px;
background: rgba(111, 151, 189, 0.045);
}
.metric::after {
position: absolute;
right: -24px;
bottom: -34px;
width: 90px;
height: 70px;
content: "";
border-radius: 50%;
background: currentColor;
opacity: 0.055;
filter: blur(8px);
}
.metric span {
display: block;
color: #8195ac;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.metric strong {
display: block;
margin-top: 2px;
color: currentColor;
font-size: 20px;
font-weight: 620;
font-variant-numeric: tabular-nums;
letter-spacing: -0.025em;
}
.metric small {
display: block;
margin-top: 1px;
color: #647991;
font-size: 9px;
}
.metric.actual {
color: var(--actual);
}
.metric.angle-a {
color: var(--angle-a);
}
.metric.angle-b {
color: var(--angle-b);
}
.hint {
right: 24px;
bottom: 23px;
z-index: 4;
color: rgba(157, 177, 199, 0.55);
font-size: 9px;
letter-spacing: 0.08em;
text-transform: uppercase;
pointer-events: none;
}
.world-label {
position: absolute;
top: 0;
left: 0;
padding: 5px 8px;
border: 1px solid rgba(157, 189, 219, 0.2);
border-radius: 7px;
background: rgba(5, 10, 24, 0.72);
box-shadow: 0 6px 22px rgba(0, 0, 0, 0.28);
color: #d9e7f3;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.1em;
line-height: 1.15;
text-transform: uppercase;
white-space: nowrap;
transform: translate(-50%, -50%);
transition: opacity 120ms;
}
.world-label small {
display: block;
margin-top: 3px;
color: #6f849d;
font-size: 7px;
font-weight: 650;
letter-spacing: 0.06em;
}
.world-label::before {
display: inline-block;
width: 5px;
height: 5px;
margin-right: 6px;
border-radius: 50%;
content: "";
background: currentColor;
box-shadow: 0 0 8px currentColor;
vertical-align: 1px;
}
.label-star {
border-color: rgba(255, 227, 154, 0.26);
color: var(--sight);
}
.label-a {
border-color: rgba(255, 99, 159, 0.27);
color: var(--angle-a);
}
.label-b {
border-color: rgba(165, 138, 255, 0.28);
color: var(--angle-b);
}
.label-actual {
border-color: rgba(57, 230, 195, 0.28);
color: var(--actual);
}
.label-grid {
border-color: rgba(49, 93, 121, 0.4);
background: rgba(5, 15, 28, 0.55);
color: #73a5bd;
}
.label-angle {
padding: 4px 7px;
border-radius: 999px;
font-size: 8px;
}
@media (max-width: 900px) {
.toggles {
display: none;
}
}
@media (max-width: 700px) {
.intro {
top: 15px;
left: 15px;
width: calc(100vw - 30px);
}
.intro p {
display: none;
}
.legend {
top: auto;
right: 12px;
bottom: 190px;
left: 12px;
display: flex;
width: auto;
gap: 13px;
overflow-x: auto;
padding: 8px 10px;
}
.legend-title,
.legend-note,
.legend-row small {
display: none;
}
.legend-row {
min-height: 18px;
font-size: 9px;
white-space: nowrap;
}
.dock {
bottom: 10px;
width: calc(100vw - 20px);
padding: 10px;
}
.control-row {
flex-wrap: wrap;
}
.scrubber {
order: 3;
flex-basis: 100%;
grid-template-columns: auto 1fr 38px;
margin-top: 2px;
}
.control-button.text {
display: none;
}
.metric-grid {
gap: 5px;
}
.metric {
padding: 8px;
}
.metric strong {
font-size: 17px;
}
.hint {
display: none;
}
}
@media (max-width: 430px) {
h1 {
max-width: 320px;
font-size: 30px;
}
.metric span {
font-size: 8px;
}
.metric small {
display: none;
}
}
</style>
</head>
<body>
<div id="stage"></div>
<div id="labels" aria-hidden="true">
<div class="world-label label-star" id="label-star">
Near star
<small>foreground marker</small>
</div>
<div class="world-label label-a" id="label-a">
Observer A
<small>first viewpoint</small>
</div>
<div class="world-label label-b" id="label-b">
Observer B
<small>second viewpoint</small>
</div>
<div class="world-label label-actual" id="label-actual">
Actual stellar motion
<small>world-space translation</small>
</div>
<div class="world-label label-angle label-a" id="label-angle-a"></div>
<div class="world-label label-angle label-b" id="label-angle-b"></div>
<div class="world-label label-grid" id="label-grid">
Fixed distant grid
<small>far reference plane</small>
</div>
</div>
<header class="intro ui">
<div class="eyebrow">Parallax · two-viewpoint study</div>
<h1>One motion.<br>Two apparent shifts.</h1>
<p>
The <strong>teal vector</strong> is the star’s real translation in world space.
The pink and violet arcs show the 3D angles measured from each observer,
while the distant grid remains fixed.
</p>
</header>
<aside class="legend ui" aria-label="Scene legend">
<div class="legend-title">Reading the scene</div>
<div class="legend-row" style="color: var(--sight)">
<span class="swatch"></span>
<span>Current sight ray<small>observer → star → fixed grid</small></span>
</div>
<div class="legend-row" style="color: var(--initial)">
<span class="swatch dashed"></span>
<span>Initial sight ray<small>dashed reference direction</small></span>
</div>
<div class="legend-row" style="color: var(--actual)">
<span class="swatch"></span>
<span>Actual stellar motion<small>physical translation vector</small></span>
</div>
<div class="legend-row" style="color: var(--angle-a)">
<span class="swatch arc"></span>
<span>Apparent angular shift<small>angle measured at the eye</small></span>
</div>
<div class="legend-row" style="color: var(--grid)">
<span class="swatch"></span>
<span>Distant reference grid<small>fixed background plane</small></span>
</div>
<div class="legend-note">
Near objects move across the background by different amounts depending on
where they are observed.
</div>
</aside>
<section class="dock ui" aria-label="Scene controls">
<div class="control-row">
<div class="transport">
<button class="control-button primary" id="play" type="button" aria-label="Pause motion">❚❚</button>
<button class="control-button" id="zoom-out" type="button" aria-label="Zoom out">−</button>
<button class="control-button" id="zoom-in" type="button" aria-label="Zoom in">+</button>
<button class="control-button text" id="reset-view" type="button">Reset view</button>
</div>
<div class="scrubber">
<label for="motion">Motion timeline</label>
<input id="motion" type="range" min="0" max="100" value="55" step="0.1">
<output id="motion-value" for="motion">55%</output>
</div>
<div class="toggles">
<label class="toggle"><input id="toggle-lines" type="checkbox" checked> Rays</label>
<label class="toggle"><input id="toggle-angles" type="checkbox" checked> Angles</label>
<label class="toggle"><input id="toggle-actual" type="checkbox" checked> Motion</label>
</div>
</div>
<div class="metric-grid">
<div class="metric actual">
<span>Actual motion</span>
<strong id="actual-metric">0.77 u</strong>
<small>physical displacement</small>
</div>
<div class="metric angle-a">
<span>Observer A · Δθ</span>
<strong id="angle-a-metric">0.0°</strong>
<small>apparent angular shift</small>
</div>
<div class="metric angle-b">
<span>Observer B · Δθ</span>
<strong id="angle-b-metric">0.0°</strong>
<small>apparent angular shift</small>
</div>
</div>
</section>
<div class="hint ui">Drag to orbit · wheel to zoom · shift-drag to pan</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.getElementById("stage");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x050816);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.1;
stage.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
100
);
const COLORS = {
sight: 0xffe39a,
initial: 0x8fa0b7,
actual: 0x39e6c3,
angleA: 0xff639f,
angleB: 0xa58aff,
grid: 0x315d79
};
const GRID_Z = -8;
const GRID_FRONT_Z = -7.92;
const baseStarPosition = new THREE.Vector3(-0.7, 0.55, 0.15);
const currentStarPosition = baseStarPosition.clone();
const maximumMotion = 1.4;
const observers = [
{
id: "A",
position: new THREE.Vector3(-2.7, -2.55, 3.2),
color: COLORS.angleA,
css: "#ff639f"
},
{
id: "B",
position: new THREE.Vector3(3.6, -2.55, 3.2),
color: COLORS.angleB,
css: "#a58aff"
}
];
function makeLine(material, pointCount = 2) {
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.BufferAttribute(new Float32Array(pointCount * 3), 3)
);
const line = new THREE.Line(geometry, material);
line.frustumCulled = false;
return line;
}
function setLinePoints(line, points) {
const attribute = line.geometry.getAttribute("position");
for (let i = 0; i < points.length; i++) {
attribute.setXYZ(i, points[i].x, points[i].y, points[i].z);
}
attribute.needsUpdate = true;
line.geometry.computeBoundingSphere();
}
// Fixed distant grid.
const backgroundPlane = new THREE.Mesh(
new THREE.PlaneGeometry(26, 13),
new THREE.MeshBasicMaterial({
color: 0x07172b,
transparent: true,
opacity: 0.68,
depthWrite: false
})
);
backgroundPlane.position.z = GRID_Z - 0.06;
scene.add(backgroundPlane);
const gridPositions = [];
for (let x = -13; x <= 13; x += 1) {
gridPositions.push(x, -6.5, GRID_Z, x, 6.5, GRID_Z);
}
for (let y = -6.5; y <= 6.5; y += 1) {
gridPositions.push(-13, y, GRID_Z, 13, y, GRID_Z);
}
const gridGeometry = new THREE.BufferGeometry();
gridGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(gridPositions, 3)
);
const grid = new THREE.LineSegments(
gridGeometry,
new THREE.LineBasicMaterial({
color: COLORS.grid,
transparent: true,
opacity: 0.36
})
);
scene.add(grid);
const axesGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-13, 0, GRID_Z + 0.01),
new THREE.Vector3(13, 0, GRID_Z + 0.01),
new THREE.Vector3(0, -6.5, GRID_Z + 0.01),
new THREE.Vector3(0, 6.5, GRID_Z + 0.01)
]);
scene.add(
new THREE.Line(
axesGeometry,
new THREE.LineBasicMaterial({
color: 0x4383a3,
transparent: true,
opacity: 0.52
})
)
);
// Stable pseudo-random distant points.
let seed = 7823;
function random() {
seed = (seed * 16807) % 2147483647;
return (seed - 1) / 2147483646;
}
const starPositions = [];
const starColors = [];
for (let i = 0; i < 260; i++) {
const x = -12.5 + random() * 25;
const y = -6.1 + random() * 12.2;
const z = GRID_Z + 0.03 + random() * 0.12;
starPositions.push(x, y, z);
const tint = random();
const color = new THREE.Color().setHSL(0.55 + tint * 0.08, 0.35, 0.55 + random() * 0.25);
starColors.push(color.r, color.g, color.b);
}
const distantPointGeometry = new THREE.BufferGeometry();
distantPointGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(starPositions, 3)
);
distantPointGeometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(starColors, 3)
);
scene.add(
new THREE.Points(
distantPointGeometry,
new THREE.PointsMaterial({
size: 0.055,
sizeAttenuation: true,
vertexColors: true,
transparent: true,
opacity: 0.75,
depthWrite: false
})
)
);
// Near star marker.
const starGroup = new THREE.Group();
scene.add(starGroup);
const starCore = new THREE.Mesh(
new THREE.SphereGeometry(0.31, 32, 24),
new THREE.MeshBasicMaterial({ color: 0xffefad })
);
starGroup.add(starCore);
const starShell = new THREE.Mesh(
new THREE.SphereGeometry(0.49, 24, 18),
new THREE.MeshBasicMaterial({
color: 0xffc85c,
transparent: true,
opacity: 0.12,
blending: THREE.AdditiveBlending,
depthWrite: false
})
);
starGroup.add(starShell);
const starRing = new THREE.Mesh(
new THREE.TorusGeometry(0.58, 0.015, 8, 80),
new THREE.MeshBasicMaterial({
color: 0xffe6a1,
transparent: true,
opacity: 0.72,
depthTest: false,
depthWrite: false
})
);
starRing.renderOrder = 8;
starGroup.add(starRing);
function createGlowTexture() {
const canvas = document.createElement("canvas");
canvas.width = 128;
canvas.height = 128;
const context = canvas.getContext("2d");
const gradient = context.createRadialGradient(64, 64, 0, 64, 64, 64);
gradient.addColorStop(0, "rgba(255,255,235,1)");
gradient.addColorStop(0.12, "rgba(255,220,130,0.82)");
gradient.addColorStop(0.38, "rgba(255,165,70,0.25)");
gradient.addColorStop(1, "rgba(255,120,40,0)");
context.fillStyle = gradient;
context.fillRect(0, 0, 128, 128);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
return texture;
}
const starGlow = new THREE.Sprite(
new THREE.SpriteMaterial({
map: createGlowTexture(),
color: 0xffd27a,
transparent: true,
opacity: 0.72,
blending: THREE.AdditiveBlending,
depthTest: false,
depthWrite: false
})
);
starGlow.scale.set(2.65, 2.65, 1);
starGlow.renderOrder = 7;
starGroup.add(starGlow);
// Actual translation layer.
const actualGroup = new THREE.Group();
scene.add(actualGroup);
const initialPositionMarker = new THREE.Group();
const initialRing = new THREE.Mesh(
new THREE.TorusGeometry(0.19, 0.018, 8, 40),
new THREE.MeshBasicMaterial({
color: COLORS.actual,
transparent: true,
opacity: 0.9,
depthTest: false,
depthWrite: false
})
);
initialRing.renderOrder = 9;
initialPositionMarker.add(initialRing);
initialPositionMarker.position.copy(baseStarPosition);
actualGroup.add(initialPositionMarker);
const motionArrow = new THREE.ArrowHelper(
new THREE.Vector3(1, 0, 0),
baseStarPosition,
1,
COLORS.actual,
0.18,
0.11
);
motionArrow.line.material.depthTest = false;
motionArrow.line.material.depthWrite = false;
motionArrow.line.material.transparent = true;
motionArrow.line.material.opacity = 0.9;
motionArrow.cone.material.depthTest = false;
motionArrow.cone.material.depthWrite = false;
motionArrow.renderOrder = 10;
actualGroup.add(motionArrow);
// Observer markers, sight rays, angular arcs, and grid-crossing markers.
const sightGroup = new THREE.Group();
const angleGroup = new THREE.Group();
scene.add(sightGroup, angleGroup);
function createObserverMarker(observer) {
const group = new THREE.Group();
group.position.copy(observer.position);
const point = new THREE.Mesh(
new THREE.SphereGeometry(0.12, 18, 12),
new THREE.MeshBasicMaterial({ color: observer.color })
);
point.renderOrder = 9;
group.add(point);
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.31, 0.023, 8, 48),
new THREE.MeshBasicMaterial({
color: observer.color,
transparent: true,
opacity: 0.88,
depthTest: false,
depthWrite: false
})
);
ring.renderOrder = 9;
group.add(ring);
const stemGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(0, -0.68, 0),
new THREE.Vector3(0, 0.5, 0)
]);
const stem = new THREE.Line(
stemGeometry,
new THREE.LineBasicMaterial({
color: observer.color,
transparent: true,
opacity: 0.48
})
);
group.add(stem);
const base = new THREE.Mesh(
new THREE.TorusGeometry(0.27, 0.018, 8, 40),
new THREE.MeshBasicMaterial({
color: observer.color,
transparent: true,
opacity: 0.42
})
);
base.rotation.x = Math.PI / 2;
base.position.y = -0.7;
group.add(base);
scene.add(group);
return { group, ring };
}
function createCrossMarker(color, radius = 0.105) {
const group = new THREE.Group();
const material = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.85,
depthTest: false,
depthWrite: false
});
const ring = new THREE.Mesh(
new THREE.TorusGeometry(radius, 0.014, 8, 32),
material
);
ring.renderOrder = 9;
group.add(ring);
const geometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-radius * 1.6, 0, 0),
new THREE.Vector3(radius * 1.6, 0, 0),
new THREE.Vector3(0, -radius * 1.6, 0),
new THREE.Vector3(0, radius * 1.6, 0)
]);
const cross = new THREE.LineSegments(
geometry,
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity: 0.72,
depthTest: false,
depthWrite: false
})
);
cross.renderOrder = 9;
group.add(cross);
return group;
}
for (const observer of observers) {
observer.marker = createObserverMarker(observer);
observer.currentRay = makeLine(
new THREE.LineBasicMaterial({
color: COLORS.sight,
transparent: true,
opacity: 0.78,
depthTest: false,
depthWrite: false
}),
3
);
observer.currentRay.renderOrder = 5;
sightGroup.add(observer.currentRay);
observer.initialRay = makeLine(
new THREE.LineDashedMaterial({
color: COLORS.initial,
transparent: true,
opacity: 0.35,
dashSize: 0.18,
gapSize: 0.12,
depthTest: false,
depthWrite: false
}),
3
);
observer.initialRay.renderOrder = 4;
sightGroup.add(observer.initialRay);
observer.arc = makeLine(
new THREE.LineBasicMaterial({
color: observer.color,
transparent: true,
opacity: 0.96,
depthTest: false,
depthWrite: false
}),
49
);
observer.arc.renderOrder = 11;
angleGroup.add(observer.arc);
observer.currentGridMarker = createCrossMarker(COLORS.sight, 0.11);
observer.initialGridMarker = createCrossMarker(COLORS.initial, 0.085);
sightGroup.add(observer.currentGridMarker, observer.initialGridMarker);
}
function projectPointToGrid(point, observerPosition) {
const direction = point.clone().sub(observerPosition);
const t = (GRID_FRONT_Z - point.z) / direction.z;
return point.clone().addScaledVector(direction, t);
}
function updateArc(observer) {
const v0 = baseStarPosition.clone().sub(observer.position);
const v1 = currentStarPosition.clone().sub(observer.position);
const angle = Math.acos(
THREE.MathUtils.clamp(
v0.clone().normalize().dot(v1.clone().normalize()),
-1,
1
)
);
const axis = new THREE.Vector3().crossVectors(v1, v0);
if (axis.lengthSq() < 1e-10) {
axis.set(0, 0, 1);
} else {
axis.normalize();
}
const radius = 0.82;
const points = [];
const startDirection = v0.clone().normalize();
for (let i = 0; i < 49; i++) {
const t = i / 48;
const direction = startDirection
.clone()
.applyAxisAngle(axis, angle * t);
points.push(
observer.position.clone().addScaledVector(direction, radius)
);
}
setLinePoints(observer.arc, points);
const bisector = v0.clone().normalize().add(v1.clone().normalize());
if (bisector.lengthSq() < 1e-10) {
bisector.copy(startDirection);
} else {
bisector.normalize();
}
return {
angle,
labelPosition: observer.position
.clone()
.addScaledVector(bisector, radius + 0.38)
};
}
// World-space labels are projected from Three.js coordinates.
const labelElements = {
star: document.getElementById("label-star"),
a: document.getElementById("label-a"),
b: document.getElementById("label-b"),
actual: document.getElementById("label-actual"),
angleA: document.getElementById("label-angle-a"),
angleB: document.getElementById("label-angle-b"),
grid: document.getElementById("label-grid")
};
function placeLabel(element, worldPosition, offsetX = 0, offsetY = 0, enabled = true) {
if (!enabled) {
element.style.visibility = "hidden";
return;
}
const projected = worldPosition.clone().project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.12 &&
projected.x < 1.12 &&
projected.y > -1.12 &&
projected.y < 1.12;
element.style.visibility = visible ? "visible" : "hidden";
if (!visible) return;
const x = (projected.x * 0.5 + 0.5) * window.innerWidth + offsetX;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight + offsetY;
element.style.transform =
`translate(${x}px, ${y}px) translate(-50%, -50%)`;
}
// Custom camera controller: orbit, pan, wheel/pinch zoom.
const cameraState = {
target: new THREE.Vector3(0, -0.35, -1.25),
radius: 18,
theta: 0.27,
phi: 1.14
};
const defaultCamera = {
target: cameraState.target.clone(),
radius: 18,
theta: 0.27,
phi: 1.14
};
function updateCamera() {
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x + cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraState.target.y + cameraState.radius * Math.cos(cameraState.phi),
cameraState.target.z + cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
camera.updateMatrixWorld();
}
function clampTarget() {
cameraState.target.x = THREE.MathUtils.clamp(cameraState.target.x, -5, 5);
cameraState.target.y = THREE.MathUtils.clamp(cameraState.target.y, -3.5, 3.5);
cameraState.target.z = THREE.MathUtils.clamp(cameraState.target.z, -3.5, 2.5);
}
function panPixels(dx, dy) {
const scale =
(2 * cameraState.radius *
Math.tan(THREE.MathUtils.degToRad(camera.fov * 0.5))) /
window.innerHeight;
const right = new THREE.Vector3().setFromMatrixColumn(camera.matrixWorld, 0);
const up = new THREE.Vector3().setFromMatrixColumn(camera.matrixWorld, 1);
cameraState.target.addScaledVector(right, -dx * scale);
cameraState.target.addScaledVector(up, dy * scale);
clampTarget();
}
const pointers = new Map();
let lastGesture = null;
function gestureState() {
const values = [...pointers.values()];
if (values.length < 2) return null;
const dx = values[0].x - values[1].x;
const dy = values[0].y - values[1].y;
return {
distance: Math.hypot(dx, dy),
midpoint: {
x: (values[0].x + values[1].x) * 0.5,
y: (values[0].y + values[1].y) * 0.5
}
};
}
renderer.domElement.addEventListener("contextmenu", event => event.preventDefault());
renderer.domElement.addEventListener("pointerdown", event => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY,
pan: event.shiftKey || event.button === 2
});
if (pointers.size === 2) {
lastGesture = gestureState();
}
});
renderer.domElement.addEventListener("pointermove", event => {
const previous = pointers.get(event.pointerId);
if (!previous) return;
const current = {
x: event.clientX,
y: event.clientY,
pan: previous.pan
};
if (pointers.size === 1) {
const dx = current.x - previous.x;
const dy = current.y - previous.y;
if (current.pan) {
panPixels(dx, dy);
} else {
cameraState.theta -= dx * 0.005;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.005,
0.35,
Math.PI - 0.35
);
}
} else if (pointers.size === 2) {
pointers.set(event.pointerId, current);
const gesture = gestureState();
if (gesture && lastGesture) {
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * (lastGesture.distance / Math.max(gesture.distance, 1)),
9,
31
);
panPixels(
gesture.midpoint.x - lastGesture.midpoint.x,
gesture.midpoint.y - lastGesture.midpoint.y
);
}
lastGesture = gesture;
return;
}
pointers.set(event.pointerId, current);
});
function endPointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) lastGesture = null;
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener(
"wheel",
event => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
9,
31
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
cameraState.target.copy(defaultCamera.target);
cameraState.radius = defaultCamera.radius;
cameraState.theta = defaultCamera.theta;
cameraState.phi = defaultCamera.phi;
});
// UI state.
const reducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
let progress = 0.55;
let direction = 1;
let playing = !reducedMotion;
const playButton = document.getElementById("play");
const motionInput = document.getElementById("motion");
const motionValue = document.getElementById("motion-value");
const actualMetric = document.getElementById("actual-metric");
const angleAMetric = document.getElementById("angle-a-metric");
const angleBMetric = document.getElementById("angle-b-metric");
const toggleLines = document.getElementById("toggle-lines");
const toggleAngles = document.getElementById("toggle-angles");
const toggleActual = document.getElementById("toggle-actual");
function updatePlayButton() {
playButton.textContent = playing ? "❚❚" : "▶";
playButton.setAttribute("aria-label", playing ? "Pause motion" : "Play motion");
}
playButton.addEventListener("click", () => {
playing = !playing;
updatePlayButton();
});
motionInput.addEventListener("input", () => {
progress = Number(motionInput.value) / 100;
direction = 1;
});
document.getElementById("zoom-in").addEventListener("click", () => {
cameraState.radius = THREE.MathUtils.clamp(cameraState.radius * 0.88, 9, 31);
});
document.getElementById("zoom-out").addEventListener("click", () => {
cameraState.radius = THREE.MathUtils.clamp(cameraState.radius * 1.12, 9, 31);
});
document.getElementById("reset-view").addEventListener("click", () => {
cameraState.target.copy(defaultCamera.target);
cameraState.radius = defaultCamera.radius;
cameraState.theta = defaultCamera.theta;
cameraState.phi = defaultCamera.phi;
});
updatePlayButton();
function updateScene(time) {
currentStarPosition.copy(baseStarPosition);
currentStarPosition.x += maximumMotion * progress;
starGroup.position.copy(currentStarPosition);
const pulse = 1 + Math.sin(time * 0.0032) * 0.055;
starShell.scale.setScalar(pulse);
starGlow.material.opacity = 0.67 + Math.sin(time * 0.0032) * 0.07;
starRing.quaternion.copy(camera.quaternion);
const displacement = currentStarPosition.clone().sub(baseStarPosition);
const displacementLength = displacement.length();
motionArrow.visible = displacementLength > 0.005;
if (motionArrow.visible) {
motionArrow.position.copy(baseStarPosition);
motionArrow.setDirection(new THREE.Vector3(1, 0, 0));
motionArrow.setLength(
displacementLength,
Math.min(0.18, displacementLength * 0.3),
Math.min(0.11, displacementLength * 0.22)
);
}
initialRing.quaternion.copy(camera.quaternion);
let angleA = 0;
let angleB = 0;
let angleAPosition = observers[0].position.clone();
let angleBPosition = observers[1].position.clone();
for (const observer of observers) {
const currentGridProjection = projectPointToGrid(
currentStarPosition,
observer.position
);
const initialGridProjection = projectPointToGrid(
baseStarPosition,
observer.position
);
setLinePoints(observer.currentRay, [
observer.position,
currentStarPosition,
currentGridProjection
]);
setLinePoints(observer.initialRay, [
observer.position,
baseStarPosition,
initialGridProjection
]);
observer.initialRay.computeLineDistances();
observer.currentGridMarker.position.copy(currentGridProjection);
observer.initialGridMarker.position.copy(initialGridProjection);
const arcData = updateArc(observer);
if (observer.id === "A") {
angleA = arcData.angle;
angleAPosition = arcData.labelPosition;
} else {
angleB = arcData.angle;
angleBPosition = arcData.labelPosition;
}
observer.marker.ring.quaternion.copy(camera.quaternion);
}
sightGroup.visible = toggleLines.checked;
angleGroup.visible = toggleAngles.checked;
actualGroup.visible = toggleActual.checked;
const degreesA = THREE.MathUtils.radToDeg(angleA);
const degreesB = THREE.MathUtils.radToDeg(angleB);
actualMetric.textContent = `${displacementLength.toFixed(2)} u`;
angleAMetric.textContent = `${degreesA.toFixed(1)}°`;
angleBMetric.textContent = `${degreesB.toFixed(1)}°`;
labelElements.angleA.textContent = `Δθ A · ${degreesA.toFixed(1)}°`;
labelElements.angleB.textContent = `Δθ B · ${degreesB.toFixed(1)}°`;
motionInput.value = String(progress * 100);
motionValue.value = `${Math.round(progress * 100)}%`;
placeLabel(
labelElements.star,
currentStarPosition.clone().add(new THREE.Vector3(0, 0.93, 0))
);
placeLabel(
labelElements.a,
observers[0].position.clone().add(new THREE.Vector3(0, 0.76, 0)),
-10,
0
);
placeLabel(
labelElements.b,
observers[1].position.clone().add(new THREE.Vector3(0, 0.76, 0)),
10,
0
);
const actualMidpoint = baseStarPosition
.clone()
.lerp(currentStarPosition, 0.5)
.add(new THREE.Vector3(0, -0.52, 0));
placeLabel(
labelElements.actual,
actualMidpoint,
0,
0,
toggleActual.checked && displacementLength > 0.025
);
placeLabel(
labelElements.angleA,
angleAPosition,
0,
0,
toggleAngles.checked
);
placeLabel(
labelElements.angleB,
angleBPosition,
0,
0,
toggleAngles.checked
);
placeLabel(
labelElements.grid,
new THREE.Vector3(-10.6, 5.85, GRID_FRONT_Z),
0,
0
);
}
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener("resize", resize);
let previousTime = performance.now();
function animate(now) {
const delta = Math.min(0.05, (now - previousTime) / 1000);
previousTime = now;
if (playing) {
progress += direction * delta * 0.115;
if (progress >= 1) {
progress = 1;
direction = -1;
} else if (progress <= 0) {
progress = 0;
direction = 1;
}
}
updateCamera();
updateScene(now);
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```