Prompt specification
Build or customize the Three.js 3D scene "Resolution and magnification teaching tool" 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: Resolution and magnification teaching tool
Category: Science & Physics · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/resolution-and-magnification-teaching-tool-x1564
Scene Description Prompt:
Resolution and magnification teaching tool. Let users change display enlargement separately from a synthetic resolution limit; show blurred or merged features appropriately and avoid presenting the toy criterion as a full optical-system calculation. Please build this with Three.js from cdnjs in one self-contained HTML file, using low-poly forms.
Acceptance criteria: Render the main model into a visible on-screen Three.js canvas so the 3D comparison is present at the initial camera position. Keep the test pattern and resolution versus magnification explanation.
Technical checks: Draw the main model in an on-screen Three.js canvas in the initial view. Use a visible test pattern and demonstrate changes to resolution and magnification independently.
Return one complete HTML document. The file must run in a sandbox allowing inline scripts and the cdnjs Three.js r160 module. Construct procedural assets, use local event handlers and avoid remote assets, runtime network requests besides Three.js, pointer lock and native form submission. Keep the main requested geometry visible in the initial view.
Working Three.js Starter (resolution-and-magnification-teaching-tool-x1564):
```html
<!doctype html>
<html lang="pt-BR">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="color-scheme" content="dark">
<link rel="icon" href="data:,">
<title>Ampliar não é resolver — Laboratório de resolução</title>
<style>
:root {
--bg: #07111c;
--bg-soft: #0b1927;
--panel: rgba(13, 30, 44, 0.92);
--panel-strong: #102538;
--line: rgba(154, 199, 221, 0.16);
--text: #edf7fb;
--muted: #9db4c2;
--cyan: #55e1d2;
--cyan-dark: #1b8e88;
--amber: #ffbf66;
--coral: #ff786e;
--shadow: 0 24px 70px rgba(0, 0, 0, 0.34);
}
* {
box-sizing: border-box;
}
html {
min-width: 320px;
background: var(--bg);
}
body {
margin: 0;
min-height: 100vh;
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
background:
radial-gradient(circle at 12% 0%, rgba(39, 161, 160, 0.16), transparent 30rem),
radial-gradient(circle at 92% 12%, rgba(255, 190, 102, 0.10), transparent 26rem),
linear-gradient(180deg, #07131f 0%, #06101a 62%, #081621 100%);
}
button,
input {
font: inherit;
}
.shell {
width: min(1480px, calc(100% - 36px));
margin: 0 auto;
padding: 30px 0 36px;
}
header {
display: grid;
grid-template-columns: minmax(0, 1fr) auto;
gap: 28px;
align-items: end;
margin-bottom: 24px;
}
.eyebrow {
display: inline-flex;
align-items: center;
gap: 9px;
margin-bottom: 9px;
color: var(--cyan);
font-size: 0.74rem;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.eyebrow::before {
width: 25px;
height: 2px;
content: "";
background: var(--cyan);
box-shadow: 0 0 14px rgba(85, 225, 210, 0.55);
}
h1 {
max-width: 850px;
margin: 0;
font-size: clamp(2rem, 4.5vw, 4.35rem);
line-height: 0.98;
letter-spacing: -0.052em;
}
h1 span {
color: var(--cyan);
}
.intro {
max-width: 690px;
margin: 17px 0 0;
color: var(--muted);
font-size: 1.02rem;
line-height: 1.62;
}
.header-tag {
min-width: 188px;
padding: 15px 17px;
border: 1px solid var(--line);
border-radius: 16px;
color: #c7d8e0;
background: rgba(11, 27, 40, 0.72);
box-shadow: var(--shadow);
font-size: 0.83rem;
line-height: 1.5;
}
.header-tag strong {
display: block;
margin-bottom: 4px;
color: var(--amber);
font-size: 0.72rem;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.layout {
display: grid;
grid-template-columns: 310px minmax(0, 1fr);
gap: 20px;
align-items: start;
}
.panel {
border: 1px solid var(--line);
border-radius: 22px;
background: var(--panel);
box-shadow: var(--shadow);
backdrop-filter: blur(18px);
}
.controls {
position: sticky;
top: 16px;
padding: 21px;
}
.panel-title {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin: 0 0 18px;
font-size: 0.78rem;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.panel-title::after {
width: 8px;
height: 8px;
content: "";
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 14px rgba(85, 225, 210, 0.7);
}
.control-group {
padding: 17px 0;
border-top: 1px solid var(--line);
}
.control-group:first-of-type {
padding-top: 0;
border-top: 0;
}
.control-label {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
margin-bottom: 11px;
}
.control-label label {
color: #dceaf0;
font-size: 0.9rem;
font-weight: 750;
}
output {
min-width: 64px;
color: var(--cyan);
font-variant-numeric: tabular-nums;
font-size: 0.9rem;
font-weight: 850;
text-align: right;
}
#resolutionOutput {
color: var(--amber);
}
input[type="range"] {
width: 100%;
height: 20px;
margin: 0;
accent-color: var(--cyan);
cursor: pointer;
}
#resolution {
accent-color: var(--amber);
}
.range-ends {
display: flex;
justify-content: space-between;
margin-top: 3px;
color: #718d9e;
font-size: 0.69rem;
}
.control-help {
margin: 9px 0 0;
color: var(--muted);
font-size: 0.78rem;
line-height: 1.5;
}
.toggle {
display: flex;
align-items: center;
gap: 10px;
color: #cbdbe3;
font-size: 0.84rem;
cursor: pointer;
user-select: none;
}
.toggle input {
width: 17px;
height: 17px;
accent-color: var(--cyan);
}
.reset {
width: 100%;
margin-top: 12px;
padding: 11px 14px;
border: 1px solid rgba(85, 225, 210, 0.28);
border-radius: 12px;
color: #dffbf7;
background: rgba(31, 133, 128, 0.12);
cursor: pointer;
font-size: 0.82rem;
font-weight: 750;
transition: 160ms ease;
}
.reset:hover {
border-color: rgba(85, 225, 210, 0.6);
background: rgba(31, 133, 128, 0.23);
transform: translateY(-1px);
}
.quick-read {
margin-top: 18px;
padding: 15px;
border: 1px solid rgba(255, 191, 102, 0.18);
border-radius: 15px;
background: rgba(255, 191, 102, 0.055);
}
.quick-read h2 {
margin: 0 0 7px;
color: var(--amber);
font-size: 0.76rem;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.quick-read p {
margin: 0;
color: #c2d1d9;
font-size: 0.78rem;
line-height: 1.52;
}
.stage {
min-width: 0;
}
.viewer {
position: relative;
width: 100%;
min-height: 520px;
aspect-ratio: 16 / 9;
overflow: hidden;
border: 1px solid rgba(161, 206, 225, 0.2);
border-radius: 23px;
background: #07131f;
box-shadow: var(--shadow), inset 0 0 0 1px rgba(255, 255, 255, 0.025);
isolation: isolate;
}
.viewer canvas {
position: absolute;
inset: 0;
z-index: 0;
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
cursor: grab;
}
.viewer canvas:focus-visible {
outline: 2px solid var(--cyan);
outline-offset: -4px;
}
.viewer canvas.dragging {
cursor: grabbing;
}
.view-label {
position: absolute;
z-index: 3;
top: 16px;
left: 17px;
max-width: calc(50% - 34px);
padding: 11px 13px;
border: 1px solid rgba(154, 199, 221, 0.2);
border-radius: 13px;
background: rgba(4, 14, 23, 0.74);
box-shadow: 0 10px 35px rgba(0, 0, 0, 0.2);
pointer-events: none;
backdrop-filter: blur(10px);
}
.view-label.right {
left: calc(50% + 17px);
}
.view-label strong {
display: block;
margin-bottom: 4px;
color: var(--cyan);
font-size: 0.72rem;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.view-label.right strong {
color: var(--amber);
}
.view-label span {
display: block;
color: #c4d5dd;
font-size: 0.74rem;
line-height: 1.35;
}
.divider {
position: absolute;
z-index: 2;
top: 0;
bottom: 0;
left: 50%;
width: 1px;
pointer-events: none;
background: linear-gradient(
180deg,
transparent,
rgba(178, 218, 235, 0.65) 12%,
rgba(178, 218, 235, 0.65) 88%,
transparent
);
box-shadow: 0 0 18px rgba(125, 194, 218, 0.18);
}
.viewer-hint {
position: absolute;
z-index: 3;
right: 14px;
bottom: 13px;
padding: 7px 10px;
border-radius: 9px;
color: #a9bdc8;
background: rgba(4, 13, 21, 0.68);
pointer-events: none;
font-size: 0.68rem;
backdrop-filter: blur(8px);
}
.viewer.stacked .view-label {
max-width: calc(100% - 34px);
}
.viewer.stacked .view-label.right {
top: auto;
right: auto;
bottom: 14px;
left: 17px;
}
.viewer.stacked .divider {
top: 50%;
right: 0;
bottom: auto;
left: 0;
width: 100%;
height: 1px;
background: linear-gradient(
90deg,
transparent,
rgba(178, 218, 235, 0.65) 12%,
rgba(178, 218, 235, 0.65) 88%,
transparent
);
}
.loading {
position: absolute;
z-index: 8;
inset: 0;
display: grid;
place-items: center;
color: var(--muted);
background: #07131f;
font-size: 0.82rem;
letter-spacing: 0.06em;
text-transform: uppercase;
transition: opacity 250ms ease;
}
.loading.hidden {
opacity: 0;
pointer-events: none;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 9px 18px;
align-items: center;
padding: 13px 4px 0;
color: #9fb4c0;
font-size: 0.76rem;
}
.legend-item {
display: inline-flex;
align-items: center;
gap: 7px;
}
.dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--cyan);
}
.dot.amber {
background: var(--amber);
}
.explanations {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 13px;
margin-top: 17px;
}
.explanation {
min-height: 158px;
padding: 17px;
border: 1px solid var(--line);
border-radius: 17px;
background: rgba(11, 28, 42, 0.72);
}
.explanation .number {
display: grid;
width: 28px;
height: 28px;
margin-bottom: 12px;
place-items: center;
border: 1px solid rgba(85, 225, 210, 0.28);
border-radius: 9px;
color: var(--cyan);
background: rgba(85, 225, 210, 0.08);
font-size: 0.72rem;
font-weight: 850;
}
.explanation:nth-child(2) .number {
color: var(--amber);
border-color: rgba(255, 191, 102, 0.28);
background: rgba(255, 191, 102, 0.08);
}
.explanation h2 {
margin: 0 0 7px;
font-size: 0.95rem;
}
.explanation p {
margin: 0;
color: var(--muted);
font-size: 0.78rem;
line-height: 1.55;
}
.notice {
display: grid;
grid-template-columns: auto 1fr;
gap: 13px;
align-items: start;
margin-top: 14px;
padding: 16px 18px;
border: 1px solid rgba(255, 120, 110, 0.22);
border-radius: 17px;
background: rgba(255, 120, 110, 0.055);
}
.notice-icon {
display: grid;
width: 30px;
height: 30px;
place-items: center;
border-radius: 50%;
color: #fff0ed;
background: rgba(255, 120, 110, 0.18);
font-weight: 900;
}
.notice h2 {
margin: 0 0 4px;
color: #ffd3cf;
font-size: 0.83rem;
}
.notice p {
margin: 0;
color: #b8c8d1;
font-size: 0.77rem;
line-height: 1.55;
}
footer {
display: flex;
justify-content: space-between;
gap: 24px;
margin-top: 23px;
padding: 0 4px;
color: #678494;
font-size: 0.7rem;
line-height: 1.5;
}
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border: 0;
}
@media (max-width: 1040px) {
.layout {
grid-template-columns: 1fr;
}
.controls {
position: static;
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 0 22px;
}
.controls > .panel-title,
.controls > .quick-read,
.controls > .reset,
.controls > .toggle {
grid-column: 1 / -1;
}
}
@media (max-width: 720px) {
.shell {
width: min(100% - 22px, 1480px);
padding-top: 20px;
}
header {
grid-template-columns: 1fr;
}
.header-tag {
display: none;
}
.controls {
display: block;
}
.viewer {
height: 620px;
min-height: 0;
aspect-ratio: auto;
}
.explanations {
grid-template-columns: 1fr;
}
.explanation {
min-height: 0;
}
footer {
display: block;
}
footer span {
display: block;
margin-top: 5px;
}
}
</style>
</head>
<body>
<div class="shell">
<header>
<div>
<div class="eyebrow">Laboratório visual de observação</div>
<h1>Ampliar <span>não é</span> resolver.</h1>
<p class="intro">
Altere o tamanho aparente do modelo e, separadamente, simule uma resolução de
amostragem mais grosseira. Observe como linhas próximas e pequenos detalhes
podem se fundir quando a imagem é ampliada sem resolução adicional.
</p>
</div>
<aside class="header-tag">
<strong>Comparação sincronizada</strong>
Os dois painéis usam o mesmo modelo, a mesma ampliação e a mesma câmera.
</aside>
</header>
<main class="layout">
<aside class="panel controls" aria-label="Controles do experimento">
<h2 class="panel-title">Controles</h2>
<section class="control-group">
<div class="control-label">
<label for="magnification">Ampliação exibida</label>
<output id="magnificationOutput" for="magnification">1,8×</output>
</div>
<input id="magnification" type="range" min="1" max="3.2" step="0.1" value="1.8">
<div class="range-ends">
<span>1×</span>
<span>3,2×</span>
</div>
<p class="control-help">
Muda apenas o tamanho aparente do specimen. Nenhum detalhe novo é criado.
</p>
</section>
<section class="control-group">
<div class="control-label">
<label for="resolution">Resolução sintética</label>
<output id="resolutionOutput" for="resolution">3/6</output>
</div>
<input id="resolution" type="range" min="1" max="6" step="1" value="3">
<div class="range-ends">
<span>fina</span>
<span>grosseira</span>
</div>
<p class="control-help">
No painel B, aumenta a coarseness da amostragem: pares de linhas e
marcações próximas podem se Joiningar ou desaparecer.
</p>
</section>
<section class="control-group">
<label class="toggle" for="showPattern">
<input id="showPattern" type="checkbox" checked>
Mostrar padrão de teste
</label>
</section>
<button class="reset" id="reset" type="button">Restaurar valores e vista</button>
<section class="quick-read">
<h2>Leitura rápida</h2>
<p id="quickText">
A ampliação aumenta o objeto. O limite sintético de resolução mantém a
cena, mas torna a amostragem visivelmente mais grossa.
</p>
</section>
</aside>
<section class="stage" aria-label="Comparação tridimensional">
<div id="viewer" class="viewer">
<div class="loading" id="loading">Preparando cena WebGL…</div>
<div class="view-label left">
<strong>A · Só ampliação</strong>
<span id="leftDetail">1,8× · sem reamostragem sintética</span>
</div>
<div class="view-label right">
<strong>B · Resolução sintética</strong>
<span id="rightDetail">1,8× · amostragem no nível 3/6</span>
</div>
<div class="divider" aria-hidden="true"></div>
<div class="viewer-hint">Arraste para orbitar · roda para aproximar · setas no teclado</div>
</div>
<div class="legend" aria-label="Legenda">
<span class="legend-item"><i class="dot"></i> painel direto: ampliação preserva a amostragem</span>
<span class="legend-item"><i class="dot amber"></i> painel WebGL reamostrado: resolução sintética mais baixa</span>
</div>
<div class="explanations">
<article class="explanation">
<div class="number">01</div>
<h2>Ampliação muda o tamanho</h2>
<p>
O specimen fica maior no campo de visão, mas seus vértices, antennas e
cores continuam sendo os mesmos. Uma imagem grande pode conter
pouca informação nova.
</p>
</article>
<article class="explanation">
<div class="number">02</div>
<h2>Resolução controla a separabilidade</h2>
<p>
No limite sintético, uma grade de amostragem mais grossa atravessa
o modelo. Detalhes vizinhos passam a ocupar a mesma amostra e podem
se Joiningar, exatamente como两块 blobs na visualização.
</p>
</article>
<article class="explanation">
<div class="number">03</div>
<h2>O padrão revela a diferença</h2>
<p>
Pares de linhas, anéis e patches coloridos servem como referência
visual. Compare a nitidez do cartão no painel A com a perda de
separação no painel B.
</p>
</article>
</div>
<aside class="notice">
<div class="notice-icon" aria-hidden="true">!</div>
<div>
<h2>Limite do modelo didático</h2>
<p>
A resolução aqui é uma simulação visual por reamostragem em baixa
resolução. Esta ferramenta não calcula MTF, difração, aberrações,
amostragem de sensor, magnificação de ocular ou desempenho de uma
cadeia óptica completa.
</p>
</div>
</aside>
<p class="sr-only" id="liveStatus" aria-live="polite"></p>
</section>
</main>
<footer>
<span>Experimento 3D em WebGL · geometrias procedurais de baixo polígono</span>
<span>Ampliação e resolução são controles independentes nesta demonstração.</span>
</footer>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const viewer = document.getElementById("viewer");
const loading = document.getElementById("loading");
const magnificationInput = document.getElementById("magnification");
const resolutionInput = document.getElementById("resolution");
const showPatternInput = document.getElementById("showPattern");
const magnificationOutput = document.getElementById("magnificationOutput");
const resolutionOutput = document.getElementById("resolutionOutput");
const leftDetail = document.getElementById("leftDetail");
const rightDetail = document.getElementById("rightDetail");
const quickText = document.getElementById("quickText");
const liveStatus = document.getElementById("liveStatus");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.setClearColor(0x07131f, 1);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.autoClear = false;
renderer.domElement.setAttribute("role", "img");
renderer.domElement.setAttribute(
"aria-label",
"Comparação WebGL de um modelo tridimensional ampliado e de sua versão com resolução sintética reduzida"
);
renderer.domElement.setAttribute("data-renderer", "threejs-webgl");
renderer.domElement.tabIndex = 0;
viewer.appendChild(renderer.domElement);
const sceneA = new THREE.Scene();
const sceneB = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(43, 1, 0.1, 100);
const postScene = new THREE.Scene();
const postCamera = new THREE.OrthographicCamera(-1, 1, 1, -1, 0, 2);
postCamera.position.z = 1;
const lowResolutionTarget = new THREE.WebGLRenderTarget(256, 256, {
minFilter: THREE.LinearFilter,
magFilter: THREE.LinearFilter,
format: THREE.RGBAFormat,
depthBuffer: true,
stencilBuffer: false
});
lowResolutionTarget.texture.generateMipmaps = false;
const postMaterial = new THREE.MeshBasicMaterial({
map: lowResolutionTarget.texture,
depthTest: false,
depthWrite: false,
toneMapped: false
});
const postQuad = new THREE.Mesh(new THREE.PlaneGeometry(2, 2), postMaterial);
postScene.add(postQuad);
const sampleFactors = [1, 1.65, 2.55, 3.75, 5.15, 6.8];
const resolutionNames = ["muito fina", "fina", "média", "baixa", "muito baixa", "grosseira"];
function flatMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.72,
metalness: 0.05,
flatShading: true,
...options
});
}
function createPatternTexture() {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 1024;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "#edf1e9";
ctx.fillRect(0, 0, 1024, 1024);
ctx.fillStyle = "#102534";
ctx.fillRect(0, 0, 1024, 104);
ctx.fillStyle = "#f5fbf8";
ctx.font = "700 40px sans-serif";
ctx.fillText("ALVO SINTÉTICO 04", 36, 66);
ctx.fillStyle = "#55e1d2";
ctx.fillRect(884, 25, 104, 54);
ctx.fillStyle = "#172a36";
ctx.font = "700 23px sans-serif";
ctx.fillText("PARES DE LINHAS", 34, 146);
ctx.fillText("PATCHES DE COR", 552, 146);
ctx.fillStyle = "#f9fbf7";
ctx.fillRect(30, 164, 478, 294);
ctx.strokeStyle = "#a9b7b7";
ctx.lineWidth = 3;
ctx.strokeRect(30, 164, 478, 294);
const gaps = [5, 10, 18, 32];
ctx.strokeStyle = "#101820";
ctx.lineWidth = 4;
gaps.forEach((gap, index) => {
const y = 205 + index * 66;
ctx.beginPath();
ctx.moveTo(62, y - gap / 2);
ctx.lineTo(468, y - gap / 2);
ctx.moveTo(62, y + gap / 2);
ctx.lineTo(468, y + gap / 2);
ctx.stroke();
ctx.fillStyle = "#4c626d";
ctx.font = "600 18px sans-serif";
ctx.fillText(`${index + 1}`, 44, y + 6);
});
const colors = [
"#e95047", "#f2bd45", "#41b9a8", "#3b78b5", "#8f63b8",
"#d9e5df", "#1d2932", "#f28c55", "#6ec46e", "#d665a7"
];
for (let row = 0; row < 5; row++) {
for (let col = 0; col < 5; col++) {
const x = 550 + col * 88;
const y = 170 + row * 58;
ctx.fillStyle = colors[(row * 5 + col) % colors.length];
ctx.fillRect(x, y, 76, 45);
ctx.strokeStyle = "rgba(255,255,255,0.55)";
ctx.lineWidth = 2;
ctx.strokeRect(x + 1, y + 1, 74, 43);
}
}
ctx.fillStyle = "#172a36";
ctx.font = "700 23px sans-serif";
ctx.fillText("ALVO CONCÊNTRICO", 34, 504);
ctx.fillStyle = "#f9fbf7";
ctx.fillRect(30, 520, 478, 414);
ctx.strokeStyle = "#a9b7b7";
ctx.lineWidth = 3;
ctx.strokeRect(30, 520, 478, 414);
ctx.save();
ctx.translate(268, 726);
for (let r = 178; r >= 18; r -= 20) {
ctx.beginPath();
ctx.arc(0, 0, r, 0, Math.PI * 2);
ctx.strokeStyle = r % 40 === 18 ? "#e84e44" : "#15212a";
ctx.lineWidth = r % 40 === 18 ? 5 : 3;
ctx.stroke();
}
ctx.fillStyle = "#15212a";
ctx.beginPath();
ctx.arc(0, 0, 7, 0, Math.PI * 2);
ctx.fill();
ctx.restore();
ctx.fillStyle = "#172a36";
ctx.font = "700 23px sans-serif";
ctx.fillText("XADREZ FINO", 548, 504);
const cell = 25;
for (let y = 0; y < 12; y++) {
for (let x = 0; x < 17; x++) {
ctx.fillStyle = (x + y) % 2 === 0 ? "#14232d" : "#eef2e9";
ctx.fillRect(548 + x * cell, 520 + y * cell, cell, cell);
}
}
ctx.fillStyle = "#172a36";
ctx.fillRect(0, 968, 1024, 56);
ctx.fillStyle = "#dfeae8";
ctx.font = "600 20px sans-serif";
ctx.fillText("REFERÊNCIA VISUAL · NÃO É MEDIÇÃO ÓPTICA", 30, 1005);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearMipmapLinearFilter;
texture.magFilter = THREE.LinearFilter;
texture.generateMipmaps = true;
texture.needsUpdate = true;
return texture;
}
const patternTexture = createPatternTexture();
function createSpecimen() {
const root = new THREE.Group();
root.name = "specimen";
const cyanMaterial = flatMaterial(0x38cfc2, { roughness: 0.56 });
const darkMaterial = flatMaterial(0x163444, { roughness: 0.62 });
const amberMaterial = flatMaterial(0xffb84d, { roughness: 0.64 });
const ivoryMaterial = flatMaterial(0xf2eee0, { roughness: 0.68 });
const coralMaterial = flatMaterial(0xff665c, { roughness: 0.6 });
const magentaMaterial = flatMaterial(0xee62a8, {
roughness: 0.48,
emissive: 0x260719,
emissiveIntensity: 0.35
});
const body = new THREE.Mesh(new THREE.OctahedronGeometry(0.95, 1), cyanMaterial);
body.scale.set(1.28, 0.76, 0.86);
body.position.y = 1.38;
body.castShadow = true;
root.add(body);
const lowerShell = new THREE.Mesh(new THREE.IcosahedronGeometry(0.63, 0), darkMaterial);
lowerShell.scale.set(1.15, 0.42, 0.86);
lowerShell.position.set(0, 0.98, 0);
lowerShell.castShadow = true;
root.add(lowerShell);
const head = new THREE.Mesh(new THREE.IcosahedronGeometry(0.5, 0), ivoryMaterial);
head.position.set(0, 2.02, 0.22);
head.scale.set(1, 0.9, 1.05);
head.castShadow = true;
root.add(head);
const beak = new THREE.Mesh(new THREE.ConeGeometry(0.2, 0.62, 4), coralMaterial);
beak.rotation.x = Math.PI / 2;
beak.rotation.y = Math.PI / 4;
beak.position.set(0, 1.96, 0.78);
beak.castShadow = true;
root.add(beak);
const leftWing = new THREE.Mesh(new THREE.ConeGeometry(0.78, 1.75, 3), amberMaterial);
leftWing.rotation.z = Math.PI / 2;
leftWing.scale.z = 0.58;
leftWing.position.set(-1.08, 1.38, -0.02);
leftWing.castShadow = true;
root.add(leftWing);
const rightWing = leftWing.clone();
rightWing.rotation.z = -Math.PI / 2;
rightWing.position.x = 1.08;
root.add(rightWing);
for (let i = -1; i <= 1; i++) {
const feather = new THREE.Mesh(new THREE.BoxGeometry(0.22, 0.72, 0.14), amberMaterial);
feather.position.set(i * 0.22, 1.18, -0.84);
feather.rotation.x = -0.28;
feather.rotation.z = i * 0.16;
feather.castShadow = true;
root.add(feather);
}
const legGeometry = new THREE.CylinderGeometry(0.065, 0.085, 0.67, 6);
for (const side of [-1, 1]) {
const leg = new THREE.Mesh(legGeometry, darkMaterial);
leg.position.set(side * 0.43, 0.58, 0.04);
leg.castShadow = true;
root.add(leg);
const foot = new THREE.Mesh(new THREE.BoxGeometry(0.31, 0.08, 0.19), coralMaterial);
foot.position.set(side * 0.43, 0.22, 0.12);
foot.castShadow = true;
root.add(foot);
}
const eyeGeometry = new THREE.SphereGeometry(0.075, 8, 5);
for (const side of [-1, 1]) {
const eye = new THREE.Mesh(eyeGeometry, magentaMaterial);
eye.position.set(side * 0.29, 2.09, 0.62);
root.add(eye);
}
const antenna = new THREE.Mesh(
new THREE.CylinderGeometry(0.025, 0.038, 0.72, 5),
darkMaterial
);
antenna.position.set(0, 2.49, 0.04);
antenna.rotation.z = -0.12;
antenna.castShadow = true;
root.add(antenna);
const tip = new THREE.Mesh(new THREE.OctahedronGeometry(0.105, 0), magentaMaterial);
tip.position.set(0.08, 2.84, 0.04);
root.add(tip);
const fiducialGeometry = new THREE.OctahedronGeometry(0.065, 0);
const fiducialPositions = [
[-0.52, 1.58, 0.63], [-0.26, 1.33, 0.70], [0, 1.50, 0.74],
[0.27, 1.62, 0.66], [0.53, 1.39, 0.62], [-0.64, 1.17, 0.55],
[0.63, 1.18, 0.54], [0.02, 1.12, 0.72]
];
fiducialPositions.forEach((position, index) => {
const marker = new THREE.Mesh(
fiducialGeometry,
index % 3 === 0 ? coralMaterial : index % 3 === 1 ? ivoryMaterial : magentaMaterial
);
marker.position.set(...position);
marker.rotation.set(index * 0.3, index * 0.47, index * 0.19);
root.add(marker);
});
return root;
}
function addEnvironment(scene, specimen, patternGroup) {
scene.background = new THREE.Color(0x081722);
scene.fog = new THREE.Fog(0x081722, 13, 28);
const hemi = new THREE.HemisphereLight(0xc9f7ff, 0x162331, 2.1);
scene.add(hemi);
const key = new THREE.DirectionalLight(0xfff3d8, 3.4);
key.position.set(4.5, 8, 6);
key.castShadow = true;
key.shadow.mapSize.set(1024, 1024);
key.shadow.camera.left = -8;
key.shadow.camera.right = 8;
key.shadow.camera.top = 9;
key.shadow.camera.bottom = -3;
key.shadow.camera.near = 1;
key.shadow.camera.far = 24;
key.shadow.bias = -0.0005;
scene.add(key);
const rim = new THREE.DirectionalLight(0x54d9e2, 1.9);
rim.position.set(-5, 4, -4);
scene.add(rim);
const fill = new THREE.PointLight(0xff9c61, 1.6, 12, 2);
fill.position.set(4, 2.2, 2.5);
scene.add(fill);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(30, 30),
flatMaterial(0x0b1e2a, { roughness: 0.96 })
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.025;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(18, 18, 0x315267, 0x183340);
grid.position.y = 0.005;
grid.material.transparent = true;
grid.material.opacity = 0.48;
scene.add(grid);
const pedestal = new THREE.Mesh(
new THREE.CylinderGeometry(1.34, 1.55, 0.34, 12),
flatMaterial(0x183545, { roughness: 0.8 })
);
pedestal.position.set(0.85, 0.17, 0);
pedestal.castShadow = true;
pedestal.receiveShadow = true;
scene.add(pedestal);
const topDisk = new THREE.Mesh(
new THREE.CylinderGeometry(1.22, 1.22, 0.055, 12),
flatMaterial(0x245062, { roughness: 0.68 })
);
topDisk.position.set(0.85, 0.365, 0);
topDisk.receiveShadow = true;
scene.add(topDisk);
const ring = new THREE.Mesh(
new THREE.TorusGeometry(1.12, 0.025, 4, 32),
new THREE.MeshBasicMaterial({ color: 0x55e1d2 })
);
ring.rotation.x = Math.PI / 2;
ring.position.set(0.85, 0.405, 0);
scene.add(ring);
specimen.position.set(0.85, 0.4, 0);
scene.add(specimen);
scene.add(patternGroup);
}
function createPatternGroup() {
const group = new THREE.Group();
group.name = "patternGroup";
const base = new THREE.Mesh(
new THREE.CylinderGeometry(0.62, 0.72, 0.12, 10),
flatMaterial(0x183545)
);
base.position.set(-2.65, 0.06, -0.35);
base.castShadow = true;
base.receiveShadow = true;
group.add(base);
const post = new THREE.Mesh(
new THREE.CylinderGeometry(0.055, 0.075, 1.55, 8),
flatMaterial(0x29485a)
);
post.position.set(-2.65, 0.82, -0.39);
post.castShadow = true;
group.add(post);
const frame = new THREE.Mesh(
new THREE.BoxGeometry(2.55, 2.55, 0.13),
flatMaterial(0x0e202c)
);
frame.position.set(-2.65, 2.3, -0.43);
frame.castShadow = true;
group.add(frame);
const pattern = new THREE.Mesh(
new THREE.PlaneGeometry(2.39, 2.39),
new THREE.MeshBasicMaterial({ map: patternTexture, toneMapped: false })
);
pattern.position.set(-2.65, 2.3, -0.355);
group.add(pattern);
return group;
}
const specimenA = createSpecimen();
const specimenB = createSpecimen();
const patternGroupA = createPatternGroup();
const patternGroupB = createPatternGroup();
addEnvironment(sceneA, specimenA, patternGroupA);
addEnvironment(sceneB, specimenB, patternGroupB);
const orbit = {
radius: 13.6,
theta: 0.42,
phi: 1.16,
target: new THREE.Vector3(-0.25, 1.78, 0)
};
const initialOrbit = { ...orbit, target: orbit.target.clone() };
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
orbit.target.y + orbit.radius * Math.cos(orbit.phi),
orbit.target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
}
let cssWidth = 1;
let cssHeight = 1;
let stacked = false;
function renderViewport(scene, x, y, width, height) {
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setViewport(x, y, width, height);
renderer.setScissor(x, y, width, height);
renderer.setScissorTest(true);
renderer.clear(true, true, true);
renderer.render(scene, camera);
}
function renderComparison() {
if (cssWidth < 2 || cssHeight < 2) return;
updateCamera();
renderer.setRenderTarget(null);
renderer.setScissorTest(false);
renderer.setViewport(0, 0, cssWidth, cssHeight);
renderer.clear(true, true, true);
if (stacked) {
const topHeight = Math.floor(cssHeight / 2);
const bottomHeight = cssHeight - topHeight;
renderViewport(sceneA, 0, bottomHeight, cssWidth, topHeight);
const factor = sampleFactors[Number(resolutionInput.value) - 1];
const targetWidth = Math.max(48, Math.floor(cssWidth / factor));
const targetHeight = Math.max(48, Math.floor(bottomHeight / factor));
lowResolutionTarget.setSize(targetWidth, targetHeight);
renderer.setScissorTest(false);
renderer.setRenderTarget(lowResolutionTarget);
camera.aspect = cssWidth / bottomHeight;
camera.updateProjectionMatrix();
renderer.clear(true, true, true);
renderer.render(sceneB, camera);
renderer.setRenderTarget(null);
renderer.setScissorTest(true);
renderer.setViewport(0, 0, cssWidth, bottomHeight);
renderer.setScissor(0, 0, cssWidth, bottomHeight);
renderer.clear(true, true, true);
renderer.render(postScene, postCamera);
} else {
const leftWidth = Math.floor(cssWidth / 2);
const rightWidth = cssWidth - leftWidth;
renderViewport(sceneA, 0, 0, leftWidth, cssHeight);
const factor = sampleFactors[Number(resolutionInput.value) - 1];
const targetWidth = Math.max(48, Math.floor(rightWidth / factor));
const targetHeight = Math.max(48, Math.floor(cssHeight / factor));
lowResolutionTarget.setSize(targetWidth, targetHeight);
renderer.setScissorTest(false);
renderer.setRenderTarget(lowResolutionTarget);
camera.aspect = rightWidth / cssHeight;
camera.updateProjectionMatrix();
renderer.clear(true, true, true);
renderer.render(sceneB, camera);
renderer.setRenderTarget(null);
renderer.setScissorTest(true);
renderer.setViewport(leftWidth, 0, rightWidth, cssHeight);
renderer.setScissor(leftWidth, 0, rightWidth, cssHeight);
renderer.clear(true, true, true);
renderer.render(postScene, postCamera);
}
renderer.setScissorTest(false);
}
function resize() {
const rect = viewer.getBoundingClientRect();
cssWidth = Math.max(1, Math.floor(rect.width));
cssHeight = Math.max(1, Math.floor(rect.height));
stacked = cssWidth < 680;
viewer.classList.toggle("stacked", stacked);
renderer.setSize(cssWidth, cssHeight, false);
renderComparison();
}
function formatMagnification(value) {
return Number(value).toFixed(1).replace(".", ",") + "×";
}
function updateExperiment(announce = false) {
const magnification = Number(magnificationInput.value);
const resolution = Number(resolutionInput.value);
specimenA.scale.setScalar(magnification);
specimenB.scale.setScalar(magnification);
magnificationOutput.textContent = formatMagnification(magnification);
resolutionOutput.textContent = `${resolution}/6`;
leftDetail.textContent = `${formatMagnification(magnification)} · sem reamostragem sintética`;
rightDetail.textContent = `${formatMagnification(magnification)} · amostragem ${resolutionNames[resolution - 1]}`;
quickText.textContent = resolution === 1
? `Com ${formatMagnification(magnification)}, o objeto ocupa mais espaço, mas o limite sintético ainda é fino. Reduza-o para observar como pares de linhas se fundem.`
: `Com ${formatMagnification(magnification)}, o objeto ocupa mais espaço. No painel B, a amostragem ${resolutionNames[resolution - 1]} faz detalhes vizinhos compartilharem células e se fundirem.`;
if (announce) {
liveStatus.textContent = `Ampliação ${formatMagnification(magnification)}. Resolução sintética nível ${resolution} de 6, ${resolutionNames[resolution - 1]}.`;
}
renderComparison();
}
function resetExperiment() {
magnificationInput.value = "1.8";
resolutionInput.value = "3";
showPatternInput.checked = true;
patternGroupA.visible = true;
patternGroupB.visible = true;
orbit.radius = initialOrbit.radius;
orbit.theta = initialOrbit.theta;
orbit.phi = initialOrbit.phi;
orbit.target.copy(initialOrbit.target);
updateExperiment(true);
}
magnificationInput.addEventListener("input", () => updateExperiment(true));
resolutionInput.addEventListener("input", () => updateExperiment(true));
showPatternInput.addEventListener("change", () => {
const visible = showPatternInput.checked;
patternGroupA.visible = visible;
patternGroupB.visible = visible;
renderComparison();
});
document.getElementById("reset").addEventListener("click", resetExperiment);
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
let activePointerId = null;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
activePointerId = event.pointerId;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.classList.add("dragging");
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging || event.pointerId !== activePointerId) return;
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
orbit.theta -= dx * 0.006;
orbit.phi = THREE.MathUtils.clamp(orbit.phi + dy * 0.005, 0.48, 1.39);
renderComparison();
});
function endDrag(event) {
if (!dragging || (event.pointerId !== undefined && event.pointerId !== activePointerId)) return;
dragging = false;
renderer.domElement.classList.remove("dragging");
if (activePointerId !== null && renderer.domElement.hasPointerCapture(activePointerId)) {
renderer.domElement.releasePointerCapture(activePointerId);
}
activePointerId = null;
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener("lostpointercapture", () => {
dragging = false;
activePointerId = null;
renderer.domElement.classList.remove("dragging");
});
renderer.domElement.addEventListener("wheel", (event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(orbit.radius + event.deltaY * 0.008, 9, 20);
renderComparison();
}, { passive: false });
renderer.domElement.addEventListener("dblclick", () => {
orbit.radius = initialOrbit.radius;
orbit.theta = initialOrbit.theta;
orbit.phi = initialOrbit.phi;
orbit.target.copy(initialOrbit.target);
renderComparison();
});
renderer.domElement.addEventListener("keydown", (event) => {
let handled = true;
if (event.key === "ArrowLeft") orbit.theta += 0.08;
else if (event.key === "ArrowRight") orbit.theta -= 0.08;
else if (event.key === "ArrowUp") orbit.phi = THREE.MathUtils.clamp(orbit.phi - 0.06, 0.48, 1.39);
else if (event.key === "ArrowDown") orbit.phi = THREE.MathUtils.clamp(orbit.phi + 0.06, 0.48, 1.39);
else if (event.key === "+" || event.key === "=") orbit.radius = THREE.MathUtils.clamp(orbit.radius - 0.8, 9, 20);
else if (event.key === "-" || event.key === "_") orbit.radius = THREE.MathUtils.clamp(orbit.radius + 0.8, 9, 20);
else if (event.key.toLowerCase() === "r") {
orbit.radius = initialOrbit.radius;
orbit.theta = initialOrbit.theta;
orbit.phi = initialOrbit.phi;
orbit.target.copy(initialOrbit.target);
} else {
handled = false;
}
if (handled) {
event.preventDefault();
renderComparison();
}
});
if ("ResizeObserver" in window) {
const resizeObserver = new ResizeObserver(resize);
resizeObserver.observe(viewer);
} else {
window.addEventListener("resize", resize);
}
updateExperiment(false);
resize();
requestAnimationFrame(() => {
renderComparison();
loading.classList.add("hidden");
});
</script>
</body>
</html>
```