Prompt specification
Build or customize the Three.js 3D scene "Festival prize-wheel teaching scene" 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: Festival prize-wheel teaching scene
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/festival-prize-wheel-teaching-scene-x1791
Scene Description Prompt:
Please use Three.js from cdnjs for a voxel scene based on this idea: festival prize-wheel teaching scene. Compose several clearly fictional prize wheels beside expected-payout and cost indicators; explain net expectation and distinguish mathematical average from guaranteed individual profit. Return one self-contained HTML file.
Technical checks: Distinguish expected net value from possible net outcomes. With a $12 entry cost and gross prizes of $0, $8, $20, and $45, show the per-round outcomes as −$12, −$4, +$8, and +$33.
Return one complete HTML document that works with the cdnjs Three.js r160 module inside a sandbox with scripts allowed. Make the requested subject visible at the default camera. Use procedural assets and local button handlers. Do not use native form submission, pointer lock, external assets or runtime requests other than Three.js.
Working Three.js Starter (festival-prize-wheel-teaching-scene-x1791):
```html
<!DOCTYPE html>
<html lang="pt-BR">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Rodas de Prêmios — Média não é garantia</title>
<style>
:root {
--bg: #080d20;
--panel: rgba(13, 20, 43, 0.88);
--panel-2: rgba(22, 31, 60, 0.84);
--line: rgba(156, 178, 255, 0.18);
--text: #f6f8ff;
--muted: #aeb9d7;
--purple: #9b87ff;
--cyan: #54d7ff;
--green: #65e6b4;
--red: #ff7f9e;
--gold: #ffd166;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button { font: inherit; }
#scene {
position: fixed;
inset: 0;
background:
radial-gradient(circle at 50% 22%, rgba(77, 70, 160, 0.24), transparent 43%),
linear-gradient(180deg, #101733 0%, #080d20 72%);
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene canvas:active { cursor: grabbing; }
.header {
position: fixed;
top: 22px;
left: 24px;
z-index: 5;
width: min(570px, calc(100vw - 48px));
pointer-events: none;
}
.eyebrow {
display: inline-flex;
align-items: center;
gap: 8px;
padding: 7px 11px;
border: 1px solid rgba(155, 135, 255, 0.35);
border-radius: 999px;
background: rgba(22, 20, 53, 0.72);
color: #d6ceff;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
backdrop-filter: blur(12px);
}
.eyebrow::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--green);
box-shadow: 0 0 14px var(--green);
}
h1 {
margin: 11px 0 6px;
font-size: clamp(27px, 3vw, 42px);
line-height: 1.03;
letter-spacing: -0.045em;
text-shadow: 0 5px 24px rgba(0, 0, 0, 0.34);
}
.header p {
max-width: 545px;
margin: 0;
color: #c4cde5;
font-size: 14px;
line-height: 1.45;
text-shadow: 0 2px 12px rgba(0, 0, 0, 0.5);
}
.top-tools {
position: fixed;
top: 22px;
right: 22px;
z-index: 8;
display: flex;
align-items: center;
gap: 10px;
}
.tool-chip,
.tool-button {
border: 1px solid var(--line);
background: rgba(12, 18, 39, 0.75);
color: var(--text);
border-radius: 12px;
backdrop-filter: blur(12px);
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18);
}
.tool-chip {
padding: 10px 13px;
color: var(--muted);
font-size: 12px;
}
.tool-button {
min-height: 39px;
padding: 0 13px;
cursor: pointer;
font-size: 12px;
font-weight: 750;
}
.tool-button:hover,
.tool-button:focus-visible {
border-color: rgba(155, 135, 255, 0.65);
background: rgba(38, 34, 76, 0.9);
outline: none;
}
.verify-badge {
position: fixed;
right: 22px;
bottom: 294px;
z-index: 7;
padding: 8px 11px;
border: 1px solid rgba(101, 230, 180, 0.32);
border-radius: 999px;
background: rgba(9, 34, 34, 0.75);
color: var(--green);
font-size: 11px;
font-weight: 800;
backdrop-filter: blur(12px);
}
.learning-dock {
position: fixed;
z-index: 10;
left: 18px;
right: 18px;
bottom: 18px;
max-height: 46vh;
display: grid;
grid-template-columns: minmax(0, 1.45fr) minmax(330px, 0.72fr);
gap: 14px;
overflow: auto;
padding: 16px;
border: 1px solid rgba(158, 175, 235, 0.2);
border-radius: 22px;
background:
linear-gradient(135deg, rgba(22, 29, 58, 0.92), rgba(9, 14, 32, 0.91));
box-shadow:
0 22px 70px rgba(0, 0, 0, 0.42),
inset 0 1px 0 rgba(255, 255, 255, 0.035);
backdrop-filter: blur(20px) saturate(120%);
}
.lesson,
.interaction {
min-width: 0;
border-radius: 16px;
background: rgba(255, 255, 255, 0.025);
}
.lesson { padding: 2px 4px 1px; }
.lesson-top {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 14px;
}
.lesson h2 {
margin: 0;
font-size: clamp(17px, 1.55vw, 23px);
line-height: 1.18;
letter-spacing: -0.025em;
}
.lesson-subtitle {
margin: 5px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.4;
}
.not-guaranteed {
flex: 0 0 auto;
padding: 7px 9px;
border: 1px solid rgba(255, 127, 158, 0.35);
border-radius: 9px;
background: rgba(92, 28, 54, 0.3);
color: #ffabc0;
font-size: 10px;
font-weight: 900;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.lesson-grid {
display: grid;
grid-template-columns: minmax(270px, 0.82fr) minmax(330px, 1.18fr);
gap: 14px;
margin-top: 12px;
align-items: start;
}
.formula-card {
padding: 12px 13px;
border: 1px solid rgba(155, 135, 255, 0.19);
border-radius: 13px;
background: rgba(13, 19, 42, 0.68);
}
.formula-label {
color: #cfc6ff;
font-size: 10px;
font-weight: 850;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.formula {
margin-top: 7px;
color: #f9f9ff;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: clamp(12px, 1.05vw, 15px);
font-weight: 700;
line-height: 1.55;
}
.formula .gross { color: var(--cyan); }
.formula .cost { color: var(--red); }
.formula .net { color: var(--green); }
.formula-note {
margin-top: 8px;
color: var(--muted);
font-size: 11px;
line-height: 1.4;
}
.probability {
display: inline-flex;
margin-top: 9px;
padding: 6px 8px;
border-radius: 8px;
background: rgba(101, 230, 180, 0.09);
color: #a8f4d6;
font-size: 11px;
font-weight: 750;
}
.outcome-wrap {
overflow: hidden;
border: 1px solid rgba(158, 175, 235, 0.16);
border-radius: 13px;
background: rgba(8, 13, 31, 0.64);
}
table {
width: 100%;
border-collapse: collapse;
font-size: 12px;
}
th {
padding: 8px 11px;
border-bottom: 1px solid var(--line);
color: var(--muted);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.07em;
text-align: right;
text-transform: uppercase;
}
th:first-child { text-align: left; }
td {
padding: 7px 11px;
border-bottom: 1px solid rgba(158, 175, 235, 0.09);
text-align: right;
font-variant-numeric: tabular-nums;
}
td:first-child { text-align: left; }
tr:last-child td { border-bottom: 0; }
tr.is-selected { background: rgba(155, 135, 255, 0.1); }
.positive { color: var(--green); }
.negative { color: var(--red); }
.callout {
margin-top: 10px;
padding: 10px 12px;
border-left: 3px solid var(--gold);
border-radius: 4px 10px 10px 4px;
background: rgba(255, 209, 102, 0.075);
color: #e8e5d6;
font-size: 11.5px;
line-height: 1.48;
}
.callout strong { color: #ffe3a2; }
.interaction {
display: flex;
flex-direction: column;
gap: 10px;
padding: 12px;
border: 1px solid rgba(158, 175, 235, 0.15);
background: rgba(7, 12, 29, 0.68);
}
.interaction-label {
color: var(--muted);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.wheel-tabs {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 6px;
}
.wheel-tab {
min-width: 0;
padding: 8px 5px;
border: 1px solid rgba(158, 175, 235, 0.14);
border-radius: 10px;
background: rgba(255, 255, 255, 0.035);
color: var(--muted);
cursor: pointer;
text-align: center;
transition: 160ms ease;
}
.wheel-tab strong,
.wheel-tab small {
display: block;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.wheel-tab strong {
color: var(--text);
font-size: 11px;
}
.wheel-tab small {
margin-top: 2px;
font-size: 9px;
}
.wheel-tab:hover:not(:disabled),
.wheel-tab:focus-visible {
border-color: rgba(155, 135, 255, 0.55);
outline: none;
}
.wheel-tab.active {
border-color: rgba(155, 135, 255, 0.8);
background: rgba(115, 91, 210, 0.2);
box-shadow: inset 0 0 0 1px rgba(155, 135, 255, 0.12);
}
.wheel-tab.active small { color: #cfc7ff; }
.result-card {
padding: 10px 11px;
border: 1px solid rgba(158, 175, 235, 0.14);
border-radius: 12px;
background: rgba(255, 255, 255, 0.028);
}
.result-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
}
.result-label {
color: var(--muted);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.mean-chip {
padding: 5px 7px;
border-radius: 7px;
background: rgba(101, 230, 180, 0.1);
color: var(--green);
font-size: 9px;
font-weight: 800;
}
.result-values {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 8px;
}
.result-values > div {
min-width: 0;
padding: 8px;
border-radius: 9px;
background: rgba(4, 8, 22, 0.52);
}
.result-values small {
display: block;
color: var(--muted);
font-size: 9px;
}
.result-values strong {
display: block;
margin-top: 3px;
overflow: hidden;
color: var(--text);
font-size: clamp(14px, 1.4vw, 20px);
line-height: 1.15;
text-overflow: ellipsis;
white-space: nowrap;
}
.result-copy {
min-height: 34px;
margin: 8px 0 0;
color: var(--muted);
font-size: 10.5px;
line-height: 1.42;
}
.button-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px;
}
.action {
min-height: 40px;
padding: 9px 10px;
border: 0;
border-radius: 10px;
cursor: pointer;
font-size: 11px;
font-weight: 850;
transition: transform 150ms ease, filter 150ms ease, opacity 150ms ease;
}
.action.primary {
background: linear-gradient(135deg, #a18bff, #6e7cff);
color: white;
box-shadow: 0 8px 22px rgba(99, 88, 220, 0.26);
}
.action.secondary {
border: 1px solid rgba(158, 175, 235, 0.2);
background: rgba(255, 255, 255, 0.055);
color: #dbe2fa;
}
.action:hover:not(:disabled),
.action:focus-visible {
filter: brightness(1.1);
transform: translateY(-1px);
outline: none;
}
.action:disabled,
.wheel-tab:disabled {
cursor: wait;
opacity: 0.5;
transform: none;
}
.sample-line {
min-height: 17px;
color: #9fb0d4;
font-size: 9.5px;
line-height: 1.4;
}
.sample-breakdown {
color: #c5cee7;
font-size: 9.5px;
}
@media (max-width: 980px) {
.learning-dock {
grid-template-columns: 1fr;
max-height: 52vh;
}
.lesson-grid {
grid-template-columns: 1fr;
}
.tool-chip { display: none; }
.verify-badge { bottom: auto; top: 130px; }
}
@media (max-width: 620px) {
.header { top: 15px; left: 15px; }
.header p { font-size: 12px; }
.top-tools { top: 15px; right: 15px; }
.tool-button { width: 40px; padding: 0; overflow: hidden; color: transparent; }
.tool-button::after { content: "↺"; color: white; font-size: 18px; }
.verify-badge { top: 126px; right: 15px; }
.learning-dock { left: 9px; right: 9px; bottom: 9px; padding: 11px; }
.lesson-top { display: block; }
.not-guaranteed { display: inline-block; margin-top: 8px; }
}
</style>
</head>
<body>
<div id="scene" role="img" aria-label="Cena tridimensional com três rodas de prêmios fictícias e indicadores de valor esperado."></div>
<header class="header">
<div class="eyebrow">Laboratório de probabilidade • jogos 100% fictícios</div>
<h1>A média não é uma promessa.</h1>
<p>
Compare o prêmio médio com o resultado de uma única rodada.
Nenhum valor esperado é um prêmio garantido.
</p>
</header>
<div class="top-tools">
<div class="tool-chip">Arraste para orbitar • role para aproximar</div>
<button id="resetCamera" class="tool-button" type="button" aria-label="Recentrar câmera">Recentrar</button>
</div>
<div id="verifyBadge" class="verify-badge">Verificando dados e geometria…</div>
<main class="learning-dock">
<section class="lesson">
<div class="lesson-top">
<div>
<h2 id="teachingTitle">Moonbeam: +$6,25 é a média, não o prêmio da rodada</h2>
<p id="teachingSubtitle" class="lesson-subtitle">Quatro resultados, cada um com probabilidade de 25%.</p>
</div>
<div class="not-guaranteed">Não garantido</div>
</div>
<div class="lesson-grid">
<div class="formula-card">
<div class="formula-label">Cálculo da média líquida</div>
<div id="formula" class="formula"></div>
<div id="formulaNote" class="formula-note"></div>
<div id="probability" class="probability"></div>
</div>
<div>
<div class="outcome-wrap">
<table aria-label="Prêmios possíveis e resultado líquido de uma rodada">
<thead>
<tr>
<th>Prêmio bruto</th>
<th>Depois do ingresso</th>
</tr>
</thead>
<tbody id="outcomeTable"></tbody>
</table>
</div>
<div id="callout" class="callout"></div>
</div>
</div>
</section>
<section class="interaction" aria-label="Teste interativo">
<div class="interaction-label">Escolha uma roda fictícia</div>
<div id="wheelTabs" class="wheel-tabs"></div>
<div class="result-card" aria-live="polite">
<div class="result-head">
<span id="resultLabel" class="result-label">Última rodada</span>
<span id="meanChip" class="mean-chip"></span>
</div>
<div class="result-values">
<div>
<small>Prêmio bruto</small>
<strong id="resultPrize">—</strong>
</div>
<div>
<small>Líquido da rodada</small>
<strong id="resultNet">—</strong>
</div>
</div>
<p id="resultCopy" class="result-copy"></p>
</div>
<div class="button-row">
<button id="spinButton" class="action primary" type="button">Girar Moonbeam</button>
<button id="sampleButton" class="action secondary" type="button">Simular 1.000</button>
</div>
<div id="sampleLine" class="sample-line">Amostra ainda não executada.</div>
<div id="sampleBreakdown" class="sample-breakdown"></div>
</section>
</main>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const WHEEL_DATA = [
{
id: "moonbeam",
name: "Moonbeam",
values: [0, 8, 20, 45],
ticket: 12,
radius: 1.80,
x: -1.30,
y: 3.20,
accent: "#9b87ff",
colors: ["#6656d8", "#e85d91", "#e4aa38", "#2eb6d8"],
boardWidth: 2.25,
boardHeight: 2.82
},
{
id: "solaris",
name: "Solaris",
values: [5, 5, 15, 25],
ticket: 10,
radius: 1.25,
x: -5.80,
y: 2.35,
accent: "#ff9d5c",
colors: ["#e85b52", "#e3ad37", "#24aa83", "#3977ca"],
boardWidth: 1.48,
boardHeight: 2.18
},
{
id: "comet",
name: "Comet",
values: [0, 0, 10, 30],
ticket: 8,
radius: 1.25,
x: 5.80,
y: 2.35,
accent: "#54d7ff",
colors: ["#7047ba", "#278ec2", "#c69d2e", "#d64e9a"],
boardWidth: 1.48,
boardHeight: 2.18
}
];
const palette = {
green: "#65e6b4",
red: "#ff7f9e",
gold: "#ffd166",
cyan: "#54d7ff",
purple: "#9b87ff",
text: "#f6f8ff",
muted: "#aeb9d7"
};
const sceneContainer = document.getElementById("scene");
const scene = new THREE.Scene();
scene.background = new THREE.Color("#080d20");
scene.fog = new THREE.Fog("#080d20", 18, 34);
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
sceneContainer.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(42, window.innerWidth / window.innerHeight, 0.1, 80);
const controls = {
radius: 17.6,
theta: 0.02,
phi: 1.22,
target: new THREE.Vector3(-0.15, 2.55, 0)
};
function updateCamera() {
const fit = Math.max(1, Math.min(1.75, 1.45 / camera.aspect));
const radius = controls.radius * fit;
const sinPhi = Math.sin(controls.phi);
camera.position.set(
controls.target.x + radius * sinPhi * Math.sin(controls.theta),
controls.target.y + radius * Math.cos(controls.phi),
controls.target.z + radius * sinPhi * Math.cos(controls.theta)
);
camera.lookAt(controls.target);
}
function resetCamera() {
controls.radius = 17.6;
controls.theta = 0.02;
controls.phi = 1.22;
controls.target.set(-0.15, 2.55, 0);
updateCamera();
}
scene.add(new THREE.HemisphereLight(0xaec5ff, 0x171127, 1.75));
const keyLight = new THREE.DirectionalLight(0xffffff, 2.4);
keyLight.position.set(4, 10, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -10;
keyLight.shadow.camera.right = 10;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -4;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x806dff, 1.7);
rimLight.position.set(-7, 5, -5);
scene.add(rimLight);
const warmLight = new THREE.PointLight(0xffa85c, 12, 13, 2);
warmLight.position.set(-5, 4, 3);
scene.add(warmLight);
const coolLight = new THREE.PointLight(0x47d8ff, 12, 13, 2);
coolLight.position.set(5, 4, 3);
scene.add(coolLight);
const groundMaterial = new THREE.MeshStandardMaterial({
color: 0x10172f,
roughness: 0.82,
metalness: 0.12
});
const ground = new THREE.Mesh(new THREE.CircleGeometry(18, 96), groundMaterial);
ground.rotation.x = -Math.PI / 2;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(28, 28, 0x33436d, 0x1b2747);
grid.position.y = 0.012;
grid.material.transparent = true;
grid.material.opacity = 0.36;
scene.add(grid);
function roundedRect(ctx, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + width, y, x + width, y + height, r);
ctx.arcTo(x + width, y + height, x, y + height, r);
ctx.arcTo(x, y + height, x, y, r);
ctx.arcTo(x, y, x + width, y, r);
ctx.closePath();
}
function formatMoney(value, signed = false) {
const absolute = Math.abs(value).toFixed(2).replace(".", ",");
if (signed) return `${value < 0 ? "−" : "+"}$${absolute}`;
return `${value < 0 ? "−" : ""}$${absolute}`;
}
function makeCanvasTexture(canvas) {
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
function makeTitleSprite(wheel) {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 256;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.textAlign = "center";
ctx.fillStyle = wheel.accent;
ctx.font = "900 76px Arial, sans-serif";
ctx.fillText(wheel.name.toUpperCase(), 512, 94);
ctx.fillStyle = "#d9dff2";
ctx.font = "700 27px Arial, sans-serif";
ctx.fillText("RODA DE PRÊMIOS FICTÍCIA", 512, 145);
ctx.fillStyle = "#8795bb";
ctx.font = "600 24px Arial, sans-serif";
ctx.fillText("4 RESULTADOS EQUIPROVÁVEIS • 25% CADA", 512, 188);
const texture = makeCanvasTexture(canvas);
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false,
toneMapped: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(3.15, 0.79, 1);
sprite.renderOrder = 20;
return sprite;
}
function makeSegmentSprite(value, color) {
const canvas = document.createElement("canvas");
canvas.width = 320;
canvas.height = 140;
const ctx = canvas.getContext("2d");
roundedRect(ctx, 7, 7, 306, 126, 28);
ctx.fillStyle = "rgba(8, 13, 31, 0.90)";
ctx.fill();
ctx.lineWidth = 6;
ctx.strokeStyle = color;
ctx.stroke();
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = "#ffffff";
ctx.font = "900 60px Arial, sans-serif";
ctx.fillText(formatMoney(value), 160, 73);
const texture = makeCanvasTexture(canvas);
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false,
toneMapped: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(0.80, 0.35, 1);
sprite.renderOrder = 12;
return sprite;
}
function makeBoardTexture(wheel) {
const canvas = document.createElement("canvas");
canvas.width = 900;
canvas.height = 1100;
const ctx = canvas.getContext("2d");
const gradient = ctx.createLinearGradient(0, 0, 900, 1100);
gradient.addColorStop(0, "#141d3d");
gradient.addColorStop(1, "#090e22");
ctx.fillStyle = gradient;
ctx.fillRect(0, 0, 900, 1100);
ctx.strokeStyle = wheel.accent;
ctx.lineWidth = 12;
roundedRect(ctx, 18, 18, 864, 1064, 36);
ctx.stroke();
ctx.textAlign = "center";
ctx.fillStyle = "#aab7d7";
ctx.font = "800 27px Arial, sans-serif";
ctx.fillText("JOGO 100% FICTÍCIO", 450, 78);
ctx.fillStyle = wheel.accent;
ctx.font = "900 64px Arial, sans-serif";
ctx.fillText(wheel.name.toUpperCase(), 450, 153);
ctx.fillStyle = "#d9e0f6";
ctx.font = "700 28px Arial, sans-serif";
ctx.fillText("4 PRÊMIOS × 25% DE CADA", 450, 198);
ctx.strokeStyle = "rgba(185, 199, 240, 0.20)";
ctx.lineWidth = 2;
ctx.beginPath();
ctx.moveTo(65, 232);
ctx.lineTo(835, 232);
ctx.stroke();
const expectedGross = wheel.values.reduce((sum, value) => sum + value, 0) / wheel.values.length;
const expectedNet = expectedGross - wheel.ticket;
ctx.textAlign = "left";
ctx.fillStyle = "#9fadd0";
ctx.font = "800 28px Arial, sans-serif";
ctx.fillText("PRÊMIO ESPERADO E[P]", 68, 295);
ctx.fillStyle = palette.cyan;
ctx.font = "900 72px Arial, sans-serif";
ctx.fillText(formatMoney(expectedGross), 68, 375);
ctx.fillStyle = "#9fadd0";
ctx.font = "800 28px Arial, sans-serif";
ctx.fillText("CUSTO / INGRESSO", 68, 468);
ctx.fillStyle = palette.red;
ctx.font = "900 62px Arial, sans-serif";
ctx.fillText(`−${formatMoney(wheel.ticket)}`, 68, 538);
ctx.fillStyle = "#9fadd0";
ctx.font = "800 28px Arial, sans-serif";
ctx.fillText("LÍQUIDO MÉDIO POR RODADA", 68, 633);
ctx.fillStyle = expectedNet >= 0 ? palette.green : palette.red;
ctx.font = "900 76px Arial, sans-serif";
ctx.fillText(formatMoney(expectedNet, true), 68, 719);
ctx.fillStyle = "#a9b6d5";
ctx.font = "800 25px Arial, sans-serif";
ctx.fillText("COMPARAÇÃO DAS MÉDIAS", 68, 790);
const maximum = Math.max(...wheel.values, wheel.ticket) * 1.15;
const barX = 68;
const barY = 820;
const barWidth = 760;
const grossWidth = barWidth * expectedGross / maximum;
const costX = barX + barWidth * wheel.ticket / maximum;
roundedRect(ctx, barX, barY, barWidth, 32, 16);
ctx.fillStyle = "rgba(255,255,255,0.10)";
ctx.fill();
roundedRect(ctx, barX, barY, grossWidth, 32, 16);
ctx.fillStyle = wheel.accent;
ctx.fill();
ctx.fillStyle = palette.red;
ctx.fillRect(costX - 4, barY - 12, 8, 56);
ctx.font = "700 24px Arial, sans-serif";
ctx.fillStyle = wheel.accent;
ctx.fillText("PRÊMIO MÉDIO", barX, 888);
ctx.textAlign = "right";
ctx.fillStyle = palette.red;
ctx.fillText("CUSTO", barX + barWidth, 888);
ctx.textAlign = "center";
ctx.fillStyle = "#f0f3ff";
ctx.font = "800 34px Arial, sans-serif";
ctx.fillText("MÉDIA DE MUITAS RODADAS", 450, 966);
roundedRect(ctx, 100, 993, 700, 48, 20);
ctx.fillStyle = "rgba(255, 127, 158, 0.12)";
ctx.fill();
ctx.fillStyle = "#ffabc0";
ctx.font = "900 25px Arial, sans-serif";
ctx.fillText("NÃO É UM PRÊMIO GARANTIDO", 450, 1026);
return makeCanvasTexture(canvas);
}
const interactiveSegments = [];
function createWheel(wheel) {
const root = new THREE.Group();
root.position.set(wheel.x, wheel.y, 0);
scene.add(root);
const rotor = new THREE.Group();
root.add(rotor);
const back = new THREE.Mesh(
new THREE.CylinderGeometry(wheel.radius * 0.98, wheel.radius * 0.98, 0.18, 64),
new THREE.MeshStandardMaterial({ color: 0x11182f, roughness: 0.72, metalness: 0.2 })
);
back.rotation.x = Math.PI / 2;
back.position.z = -0.18;
back.castShadow = true;
root.add(back);
const segments = [];
const labels = [];
for (let index = 0; index < wheel.values.length; index++) {
const start = index * Math.PI / 2 + 0.022;
const end = (index + 1) * Math.PI / 2 - 0.022;
const shape = new THREE.Shape();
shape.moveTo(0, 0);
shape.lineTo(Math.cos(start) * wheel.radius, Math.sin(start) * wheel.radius);
shape.absarc(0, 0, wheel.radius, start, end, false);
shape.lineTo(0, 0);
shape.closePath();
const geometry = new THREE.ExtrudeGeometry(shape, {
depth: 0.27,
steps: 1,
bevelEnabled: true,
bevelSegments: 2,
bevelSize: 0.025,
bevelThickness: 0.025
});
geometry.computeVertexNormals();
const material = new THREE.MeshStandardMaterial({
color: wheel.colors[index],
emissive: wheel.colors[index],
emissiveIntensity: 0.075,
roughness: 0.42,
metalness: 0.08
});
const segment = new THREE.Mesh(geometry, material);
segment.position.z = -0.135;
segment.castShadow = true;
segment.receiveShadow = true;
segment.userData = { wheelId: wheel.id, outcomeIndex: index };
rotor.add(segment);
segments.push(segment);
interactiveSegments.push(segment);
const centerAngle = index * Math.PI / 2 + Math.PI / 4;
const label = makeSegmentSprite(wheel.values[index], wheel.colors[index]);
label.position.set(
Math.cos(centerAngle) * wheel.radius * 0.56,
Math.sin(centerAngle) * wheel.radius * 0.56,
0.31
);
rotor.add(label);
labels.push(label);
}
const rim = new THREE.Mesh(
new THREE.TorusGeometry(wheel.radius + 0.045, 0.115, 14, 80),
new THREE.MeshStandardMaterial({
color: wheel.accent,
emissive: wheel.accent,
emissiveIntensity: 0.22,
roughness: 0.3,
metalness: 0.52
})
);
rim.castShadow = true;
root.add(rim);
const hub = new THREE.Mesh(
new THREE.CylinderGeometry(0.25, 0.25, 0.38, 32),
new THREE.MeshStandardMaterial({
color: 0xe8efff,
emissive: wheel.accent,
emissiveIntensity: 0.12,
roughness: 0.26,
metalness: 0.62
})
);
hub.rotation.x = Math.PI / 2;
hub.castShadow = true;
root.add(hub);
const pointerMaterial = new THREE.MeshStandardMaterial({
color: palette.gold,
emissive: palette.gold,
emissiveIntensity: 0.45,
roughness: 0.28,
metalness: 0.42
});
const pointer = new THREE.Mesh(new THREE.ConeGeometry(0.18, 0.46, 3), pointerMaterial);
pointer.rotation.z = Math.PI;
pointer.position.set(0, wheel.radius + 0.24, 0.17);
pointer.castShadow = true;
root.add(pointer);
const bulbs = [];
const bulbGeometry = new THREE.SphereGeometry(0.067, 12, 10);
for (let index = 0; index < 16; index++) {
const angle = index / 16 * Math.PI * 2;
const color = new THREE.Color(index % 2 === 0 ? wheel.accent : palette.gold);
const material = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.8,
roughness: 0.35
});
const bulb = new THREE.Mesh(bulbGeometry, material);
bulb.position.set(
Math.cos(angle) * (wheel.radius + 0.11),
Math.sin(angle) * (wheel.radius + 0.11),
0.11
);
bulb.userData.phase = index * 0.7;
root.add(bulb);
bulbs.push(bulb);
}
const title = makeTitleSprite(wheel);
title.position.set(0, wheel.radius + 0.82, 0);
title.scale.multiplyScalar(wheel.id === "moonbeam" ? 1.08 : 0.78);
root.add(title);
const platform = new THREE.Mesh(
new THREE.CylinderGeometry(wheel.radius + 0.65, wheel.radius + 0.76, 0.32, 64),
new THREE.MeshStandardMaterial({
color: 0x121a35,
emissive: wheel.accent,
emissiveIntensity: 0.035,
roughness: 0.7,
metalness: 0.22
})
);
platform.position.set(wheel.x, 0.16, 0);
platform.receiveShadow = true;
platform.castShadow = true;
scene.add(platform);
const platformRing = new THREE.Mesh(
new THREE.TorusGeometry(wheel.radius + 0.66, 0.035, 10, 72),
new THREE.MeshBasicMaterial({ color: wheel.accent, toneMapped: false })
);
platformRing.rotation.x = Math.PI / 2;
platformRing.position.set(wheel.x, 0.33, 0);
scene.add(platformRing);
const poleBottom = 0.40;
const poleTop = wheel.y - wheel.radius;
const poleHeight = Math.max(0.45, poleTop - poleBottom);
const pole = new THREE.Mesh(
new THREE.CylinderGeometry(0.13, 0.17, poleHeight, 20),
new THREE.MeshStandardMaterial({ color: 0x64739b, roughness: 0.42, metalness: 0.55 })
);
pole.position.set(wheel.x, poleBottom + poleHeight / 2, -0.33);
pole.castShadow = true;
scene.add(pole);
wheel.root = root;
wheel.rotor = rotor;
wheel.segments = segments;
wheel.labels = labels;
wheel.bulbs = bulbs;
wheel.pointerMaterial = pointerMaterial;
wheel.expectedGross = wheel.values.reduce((sum, value) => sum + value, 0) / wheel.values.length;
wheel.expectedNet = wheel.expectedGross - wheel.ticket;
}
function createBoard(wheel, x, y) {
const group = new THREE.Group();
group.position.set(x, y, 0.30);
scene.add(group);
const frame = new THREE.Mesh(
new THREE.BoxGeometry(wheel.boardWidth + 0.13, wheel.boardHeight + 0.13, 0.18),
new THREE.MeshStandardMaterial({
color: 0x0b1023,
emissive: wheel.accent,
emissiveIntensity: 0.035,
roughness: 0.44,
metalness: 0.38
})
);
frame.position.z = -0.11;
frame.castShadow = true;
group.add(frame);
const texture = makeBoardTexture(wheel);
const faceMaterial = new THREE.MeshBasicMaterial({
map: texture,
toneMapped: false
});
const face = new THREE.Mesh(
new THREE.PlaneGeometry(wheel.boardWidth, wheel.boardHeight),
faceMaterial
);
face.position.z = 0.001;
group.add(face);
const standBottom = 0.35;
const standHeight = y - wheel.boardHeight / 2 - standBottom;
if (standHeight > 0.1) {
const stand = new THREE.Mesh(
new THREE.CylinderGeometry(0.055, 0.08, standHeight, 12),
new THREE.MeshStandardMaterial({ color: 0x536387, roughness: 0.45, metalness: 0.55 })
);
stand.position.set(x, standBottom + standHeight / 2, 0.12);
stand.castShadow = true;
scene.add(stand);
}
}
WHEEL_DATA.forEach(createWheel);
createBoard(WHEEL_DATA[0], 2.00, 2.45);
createBoard(WHEEL_DATA[1], -3.90, 2.15);
createBoard(WHEEL_DATA[2], 3.65, 2.15);
function createFestoon() {
const points = [];
const count = 15;
for (let index = 0; index < count; index++) {
const t = index / (count - 1);
const x = -7.2 + t * 14.4;
const y = 7.35 - 0.75 * (1 - Math.pow(2 * t - 1, 2));
points.push(new THREE.Vector3(x, y, -1.25));
}
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const line = new THREE.Line(
geometry,
new THREE.LineBasicMaterial({ color: 0x536489, transparent: true, opacity: 0.78 })
);
scene.add(line);
points.slice(1, -1).forEach((point, index) => {
const color = new THREE.Color(index % 3 === 0 ? "#ff7fb1" : index % 3 === 1 ? "#ffd166" : "#54d7ff");
const bulb = new THREE.Mesh(
new THREE.SphereGeometry(0.085, 14, 10),
new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 1.3,
roughness: 0.25
})
);
bulb.position.copy(point).add(new THREE.Vector3(0, -0.13, 0));
scene.add(bulb);
});
}
createFestoon();
function seededRandom(seed) {
let x = seed >>> 0 || 0x6d2b79f5;
return () => {
x ^= x << 13;
x ^= x >>> 17;
x ^= x << 5;
return (x >>> 0) / 4294967296;
};
}
const starRandom = seededRandom(481516);
const starPositions = [];
for (let index = 0; index < 170; index++) {
starPositions.push(
(starRandom() - 0.5) * 25,
1 + starRandom() * 10,
-6 - starRandom() * 10
);
}
const starGeometry = new THREE.BufferGeometry();
starGeometry.setAttribute("position", new THREE.Float32BufferAttribute(starPositions, 3));
const stars = new THREE.Points(
starGeometry,
new THREE.PointsMaterial({
color: 0xa9b8ee,
size: 0.055,
transparent: true,
opacity: 0.7,
sizeAttenuation: true
})
);
scene.add(stars);
const confetti = [];
const confettiGeometry = new THREE.BoxGeometry(0.055, 0.13, 0.025);
const confettiColors = ["#9b87ff", "#54d7ff", "#ffd166", "#ff7f9e", "#65e6b4"];
for (let index = 0; index < 34; index++) {
const color = new THREE.Color(confettiColors[index % confettiColors.length]);
const piece = new THREE.Mesh(
confettiGeometry,
new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.2,
roughness: 0.5
})
);
piece.position.set(
-7 + starRandom() * 14,
0.55 + starRandom() * 4.7,
-0.8 + starRandom() * 2.2
);
piece.rotation.set(starRandom() * 3, starRandom() * 3, starRandom() * 3);
piece.userData.baseY = piece.position.y;
piece.userData.phase = starRandom() * Math.PI * 2;
scene.add(piece);
confetti.push(piece);
}
let selectedWheel = WHEEL_DATA[0];
let spinning = null;
let simulationRun = 0;
let lastSelectedOutcome = -1;
const wheelTabs = document.getElementById("wheelTabs");
const outcomeTable = document.getElementById("outcomeTable");
const teachingTitle = document.getElementById("teachingTitle");
const teachingSubtitle = document.getElementById("teachingSubtitle");
const formula = document.getElementById("formula");
const formulaNote = document.getElementById("formulaNote");
const probability = document.getElementById("probability");
const callout = document.getElementById("callout");
const resultLabel = document.getElementById("resultLabel");
const resultPrize = document.getElementById("resultPrize");
const resultNet = document.getElementById("resultNet");
const resultCopy = document.getElementById("resultCopy");
const meanChip = document.getElementById("meanChip");
const spinButton = document.getElementById("spinButton");
const sampleButton = document.getElementById("sampleButton");
const sampleLine = document.getElementById("sampleLine");
const sampleBreakdown = document.getElementById("sampleBreakdown");
const resetCameraButton = document.getElementById("resetCamera");
WHEEL_DATA.forEach(wheel => {
const button = document.createElement("button");
button.type = "button";
button.className = "wheel-tab";
button.dataset.wheel = wheel.id;
button.setAttribute("aria-pressed", "false");
button.innerHTML = `<strong>${wheel.name}</strong><small>média ${formatMoney(wheel.expectedNet, true)}</small>`;
button.addEventListener("click", () => {
if (!spinning) selectWheel(wheel.id);
});
wheelTabs.appendChild(button);
});
function clearHighlights() {
WHEEL_DATA.forEach(wheel => {
wheel.segments.forEach(segment => {
segment.material.emissiveIntensity = 0.075;
});
});
}
function setHighlight(wheel, index) {
clearHighlights();
wheel.segments[index].material.emissiveIntensity = 0.62;
}
function selectWheel(id) {
selectedWheel = WHEEL_DATA.find(wheel => wheel.id === id);
lastSelectedOutcome = -1;
clearHighlights();
document.querySelectorAll(".wheel-tab").forEach(button => {
const active = button.dataset.wheel === id;
button.classList.toggle("active", active);
button.setAttribute("aria-pressed", String(active));
});
const sum = selectedWheel.values.reduce((total, value) => total + value, 0);
const positiveCount = selectedWheel.values.filter(value => value - selectedWheel.ticket > 0).length;
const probabilityText = positiveCount / selectedWheel.values.length;
teachingTitle.textContent =
`${selectedWheel.name}: ${formatMoney(selectedWheel.expectedNet, true)} é a média, não o prêmio da rodada`;
teachingSubtitle.textContent =
`Quatro resultados, cada um com probabilidade de 25%. O ingresso custa ${formatMoney(selectedWheel.ticket)}.`;
formula.innerHTML = `
<div>E[prêmio] = (${selectedWheel.values.join(" + ")}) ÷ 4 = <span class="gross">${formatMoney(selectedWheel.expectedGross)}</span></div>
<div>E[líquido] = <span class="gross">${formatMoney(selectedWheel.expectedGross)}</span> − <span class="cost">${formatMoney(selectedWheel.ticket)}</span> = <span class="net">${formatMoney(selectedWheel.expectedNet, true)}</span></div>
`;
formulaNote.textContent =
`É a média de muitas rodadas. Uma rodada isolada entrega apenas um prêmio; a média não “cobre” as perdas individuais.`;
probability.textContent =
`Probabilidade de lucro em uma única rodada: ${positiveCount}/4 = ${(probabilityText * 100).toFixed(0)}%`;
outcomeTable.innerHTML = selectedWheel.values.map((value, index) => {
const net = value - selectedWheel.ticket;
return `
<tr data-outcome="${index}">
<td>${formatMoney(value)}</td>
<td class="${net >= 0 ? "positive" : "negative"}">${formatMoney(net, true)}</td>
</tr>
`;
}).join("");
if (selectedWheel.id === "moonbeam") {
callout.innerHTML =
`<strong>Não existe um prêmio de $6,25 na Moonbeam.</strong> Em uma rodada, o prêmio bruto é $0, $8, $20 ou $45; subtraindo o ingresso de $12, o líquido é −$12, −$4, +$8 ou +$33. Portanto, +$6,25 é somente a média líquida esperada.`;
} else {
const outcomes = selectedWheel.values
.map(value => `${formatMoney(value)} → ${formatMoney(value - selectedWheel.ticket, true)}`)
.join("; ");
callout.innerHTML =
`<strong>O valor médio não aparece como prêmio na roda.</strong> Os resultados possíveis são: ${outcomes}. Uma única rodada pode terminar abaixo do custo.`;
}
meanChip.textContent = `Média líquida ${formatMoney(selectedWheel.expectedNet, true)}`;
resultLabel.textContent = "Última rodada";
resultPrize.textContent = "—";
resultPrize.className = "";
resultNet.textContent = "—";
resultNet.className = "";
resultCopy.textContent = `Gire ${selectedWheel.name} para sortear um prêmio real desta roda fictícia.`;
spinButton.textContent = `Girar ${selectedWheel.name}`;
sampleLine.textContent = "Amostra ainda não executada.";
sampleBreakdown.textContent = "";
}
function setControlDisabled(disabled) {
spinButton.disabled = disabled;
sampleButton.disabled = disabled;
document.querySelectorAll(".wheel-tab").forEach(button => {
button.disabled = disabled;
});
}
function normalizeAngle(angle) {
return ((angle % (Math.PI * 2)) + Math.PI * 2) % (Math.PI * 2);
}
function targetRotationForOutcome(currentRotation, outcomeIndex) {
const localCenter = outcomeIndex * Math.PI / 2 + Math.PI / 4;
const desiredBase = Math.PI / 2 - localCenter;
const delta = normalizeAngle(desiredBase - currentRotation);
return currentRotation + Math.PI * 2 * 5 + delta;
}
function beginSpin() {
if (spinning) return;
const outcomeIndex = Math.floor(Math.random() * selectedWheel.values.length);
const currentRotation = selectedWheel.rotor.rotation.z;
const targetRotation = targetRotationForOutcome(currentRotation, outcomeIndex);
spinning = {
wheel: selectedWheel,
outcomeIndex,
startTime: performance.now(),
duration: 1850,
startRotation: currentRotation,
targetRotation
};
clearHighlights();
setControlDisabled(true);
resultLabel.textContent = "Sorteando…";
resultPrize.textContent = "…";
resultNet.textContent = "…";
resultCopy.textContent = "A roda está girando. O ponteiro indicará o prêmio efetivamente sorteado.";
spinButton.textContent = "Girando…";
}
function completeSpin() {
const completed = spinning;
spinning = null;
completed.wheel.rotor.rotation.z = completed.targetRotation;
setHighlight(completed.wheel, completed.outcomeIndex);
const prize = completed.wheel.values[completed.outcomeIndex];
const net = prize - completed.wheel.ticket;
if (completed.wheel.id === selectedWheel.id) {
lastSelectedOutcome = completed.outcomeIndex;
resultLabel.textContent = "Rodada sorteada";
resultPrize.textContent = formatMoney(prize);
resultPrize.className = "";
resultNet.textContent = formatMoney(net, true);
resultNet.className = net >= 0 ? "positive" : "negative";
resultCopy.textContent =
`Esta rodada paga ${formatMoney(prize)}. Depois do ingresso de ${formatMoney(completed.wheel.ticket)}, o resultado é ${formatMoney(net, true)}. A média ${formatMoney(completed.wheel.expectedNet, true)} não promete este resultado.`;
document.querySelectorAll("#outcomeTable tr").forEach(row => {
row.classList.toggle("is-selected", Number(row.dataset.outcome) === completed.outcomeIndex);
});
}
setControlDisabled(false);
spinButton.textContent = `Girar ${selectedWheel.name}`;
sampleLine.textContent = "Amostra ainda não executada.";
sampleBreakdown.textContent = "";
}
function runSimulation() {
if (spinning) return;
simulationRun++;
const seed = (0x6d2b79f5 ^ selectedWheel.id.length * 2654435761 ^ simulationRun * 2246822519) >>> 0;
const random = seededRandom(seed);
const counts = new Array(selectedWheel.values.length).fill(0);
let grossSum = 0;
let netSum = 0;
let losses = 0;
for (let index = 0; index < 1000; index++) {
const outcomeIndex = Math.floor(random() * selectedWheel.values.length);
const prize = selectedWheel.values[outcomeIndex];
const net = prize - selectedWheel.ticket;
counts[outcomeIndex]++;
grossSum += prize;
netSum += net;
if (net < 0) losses++;
}
const observedGross = grossSum / 1000;
const observedNet = netSum / 1000;
resultLabel.textContent = "Média observada em 1.000 rodadas";
resultPrize.textContent = formatMoney(observedGross);
resultPrize.className = "";
resultNet.textContent = formatMoney(observedNet, true);
resultNet.className = observedNet >= 0 ? "positive" : "negative";
resultCopy.textContent =
`A amostra teve ${losses.toLocaleString("pt-BR")} rodadas com prejuízo. A média observada é uma estimativa da média teórica ${formatMoney(selectedWheel.expectedNet, true)}; ela varia entre amostras.`;
sampleLine.textContent =
`Amostra: média bruta ${formatMoney(observedGross)} • média líquida ${formatMoney(observedNet, true)} • ${losses} rodadas negativas.`;
sampleBreakdown.textContent = selectedWheel.values
.map((value, index) => `${formatMoney(value)}: ${counts[index]}`)
.join(" • ");
}
spinButton.addEventListener("click", beginSpin);
sampleButton.addEventListener("click", runSimulation);
resetCameraButton.addEventListener("click", resetCamera);
selectWheel("moonbeam");
let pointerState = null;
let dragMoved = false;
const raycaster = new THREE.Raycaster();
const pointerNdc = new THREE.Vector2();
renderer.domElement.addEventListener("pointerdown", event => {
pointerState = {
id: event.pointerId,
startX: event.clientX,
startY: event.clientY,
lastX: event.clientX,
lastY: event.clientY
};
dragMoved = false;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!pointerState || pointerState.id !== event.pointerId) return;
const dx = event.clientX - pointerState.lastX;
const dy = event.clientY - pointerState.lastY;
if (Math.hypot(event.clientX - pointerState.startX, event.clientY - pointerState.startY) > 4) {
dragMoved = true;
}
if (dragMoved) {
controls.theta = THREE.MathUtils.clamp(controls.theta - dx * 0.0045, -0.72, 0.72);
controls.phi = THREE.MathUtils.clamp(controls.phi - dy * 0.0035, 0.86, 1.36);
updateCamera();
}
pointerState.lastX = event.clientX;
pointerState.lastY = event.clientY;
});
renderer.domElement.addEventListener("pointerup", event => {
if (!pointerState || pointerState.id !== event.pointerId) return;
if (!dragMoved && !spinning) {
const rect = renderer.domElement.getBoundingClientRect();
pointerNdc.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointerNdc.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointerNdc, camera);
const hits = raycaster.intersectObjects(interactiveSegments, false);
if (hits.length) {
const wheelId = hits[0].object.userData.wheelId;
if (wheelId !== selectedWheel.id) selectWheel(wheelId);
beginSpin();
}
}
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
pointerState = null;
});
renderer.domElement.addEventListener("pointercancel", () => {
pointerState = null;
});
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
controls.radius = THREE.MathUtils.clamp(controls.radius + event.deltaY * 0.012, 11.5, 24);
updateCamera();
}, { passive: false });
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
updateCamera();
});
function assertCondition(condition, message) {
if (!condition) throw new Error(message);
}
function runDataAndGeometryTests() {
const moonbeam = WHEEL_DATA.find(wheel => wheel.id === "moonbeam");
const moonbeamNets = moonbeam.values.map(value => value - moonbeam.ticket);
assertCondition(
JSON.stringify(moonbeamNets) === JSON.stringify([-12, -4, 8, 33]),
"Moonbeam: os líquidos por rodada estão incorretos."
);
assertCondition(
Math.abs(moonbeam.expectedGross - 18.25) < 1e-9,
"Moonbeam: o prêmio médio esperado deveria ser 18.25."
);
assertCondition(
Math.abs(moonbeam.expectedNet - 6.25) < 1e-9,
"Moonbeam: o líquido médio esperado deveria ser 6.25."
);
WHEEL_DATA.forEach(wheel => {
assertCondition(wheel.values.length === 4, `${wheel.name}: número de resultados incorreto.`);
assertCondition(wheel.segments.length === 4, `${wheel.name}: geometria não tem quatro segmentos.`);
assertCondition(
Math.abs(wheel.expectedNet - (wheel.expectedGross - wheel.ticket)) < 1e-9,
`${wheel.name}: média líquida inconsistente.`
);
for (let index = 0; index < 4; index++) {
const desired = Math.PI / 4 - index * Math.PI / 2;
const localPointerAngle = normalizeAngle(Math.PI / 2 - desired);
const selectedIndex = Math.round((localPointerAngle - Math.PI / 4) / (Math.PI / 2) + 4) % 4;
assertCondition(
selectedIndex === index,
`${wheel.name}: o ponteiro não alinha com o segmento sorteado.`
);
}
});
const badge = document.getElementById("verifyBadge");
badge.textContent = "Dados e geometria verificados ✓";
badge.style.borderColor = "rgba(101, 230, 180, 0.55)";
}
runDataAndGeometryTests();
updateCamera();
window.__sceneReady = true;
window.__festivalWheelTests = runDataAndGeometryTests;
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
if (spinning) {
const progress = THREE.MathUtils.clamp(
(performance.now() - spinning.startTime) / spinning.duration,
0,
1
);
const eased = 1 - Math.pow(1 - progress, 4);
spinning.wheel.rotor.rotation.z = THREE.MathUtils.lerp(
spinning.startRotation,
spinning.targetRotation,
eased
);
if (progress >= 1) completeSpin();
}
WHEEL_DATA.forEach(wheel => {
wheel.bulbs.forEach(bulb => {
const pulse = 0.72 + 0.48 * Math.sin(elapsed * 3.1 + bulb.userData.phase);
bulb.material.emissiveIntensity = pulse + (spinning?.wheel === wheel ? 0.7 : 0);
});
});
confetti.forEach(piece => {
piece.position.y = piece.userData.baseY + Math.sin(elapsed * 0.9 + piece.userData.phase) * 0.10;
piece.rotation.y += 0.004;
piece.rotation.z += 0.002;
});
stars.rotation.y = elapsed * 0.002;
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>
```