Leque
Feixes que saem de um canto e abrem num arco achatado; o cursor os afasta e a mola os devolve.
usa o PAR-04
O código
particulas-motor.js + leque.js + markup.html
/* ===== particulas-motor.js ========================================================= */
/* OCTA · motor de cenas de partículas — a base compartilhada pelos componentes PAR-*.
Cena de three.js atrás de uma dobra, com física leve e o cursor mandando de verdade.
Nasceu no site da primeira proposta da OCTA ao Pedro (27/08/2026), onde as seis cenas viviam
num arquivo só. Aqui o motor está separado da cena: você inclui ESTE arquivo uma vez e, depois
dele, só o arquivo da cena que for usar.
Três regras de desempenho que não são opcionais:
- **pausa fora da tela** (IntersectionObserver): cena invisível não queima bateria;
- **DPR no teto de 2**: acima disso o ganho é invisível e o custo não;
- **`prefers-reduced-motion` desenha UM quadro e para** — a cena existe, não se mexe.
Configuração, no próprio <canvas>:
data-cena="plexus" qual cena (obrigatório)
data-cor="#212121" a cor dos nós e das linhas
data-cor-destaque="#e8ad32" o acento (algumas cenas usam)
Exige three.js (r12x+) carregado antes. Sem ele, o canvas some em silêncio — a página não quebra.
*/
window.OctaParticulas = (function () {
'use strict';
var REDUZIR = window.matchMedia && window.matchMedia('(prefers-reduced-motion: reduce)').matches;
var CELULAR = window.innerWidth < 700;
var cenas = {};
function textura(desenhar) {
var cv = document.createElement('canvas');
cv.width = cv.height = 64;
desenhar(cv.getContext('2d'));
return new THREE.CanvasTexture(cv);
}
var PONTO = null, ANEL = null;
function texturas() {
if (PONTO) { return; }
PONTO = textura(function (g) { g.fillStyle = '#fff'; g.beginPath(); g.arc(32, 32, 30, 0, Math.PI * 2); g.fill(); });
ANEL = textura(function (g) { g.strokeStyle = '#fff'; g.lineWidth = 7; g.beginPath(); g.arc(32, 32, 24, 0, Math.PI * 2); g.stroke(); });
}
function Cena(canvas) {
texturas();
this.canvas = canvas;
this.tipo = canvas.getAttribute('data-cena');
this.dobra = canvas.parentElement;
this.COR = new THREE.Color(canvas.getAttribute('data-cor') || '#212121');
this.DESTAQUE = new THREE.Color(canvas.getAttribute('data-cor-destaque') || '#e8ad32');
this.PONTO = PONTO;
this.ANEL = ANEL;
this.CELULAR = CELULAR;
this.renderer = new THREE.WebGLRenderer({ canvas: canvas, alpha: true, antialias: true });
this.renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
this.scene = new THREE.Scene();
/* câmera ortográfica em PIXEL: x e y da cena são as coordenadas da tela, e a conta de
física fica legível — sem conversão de espaço no meio do passo */
this.camera = new THREE.OrthographicCamera(0, 1, 1, 0, -500, 500);
this.mouse = { x: -9999, y: -9999 };
this.t = 0;
this.rodando = false;
var eu = this;
this.dobra.addEventListener('pointermove', function (e) {
var r = eu.canvas.getBoundingClientRect();
eu.mouse.x = e.clientX - r.left;
eu.mouse.y = e.clientY - r.top;
});
this.dobra.addEventListener('pointerleave', function () { eu.mouse.x = -9999; eu.mouse.y = -9999; });
window.addEventListener('resize', function () { eu.redimensionar(); });
this.redimensionar();
var montar = cenas[this.tipo];
if (!montar) { throw new Error('cena desconhecida: ' + this.tipo); }
montar.call(this);
this.montada = true;
if (REDUZIR) { this.passo(0.016); this.desenhar(); return; }
if ('IntersectionObserver' in window) {
new IntersectionObserver(function (en) {
eu.rodando = en[0].isIntersecting;
if (eu.rodando) { eu.laco(); }
}, { rootMargin: '80px' }).observe(canvas);
} else {
this.rodando = true;
this.laco();
}
}
Cena.prototype.redimensionar = function () {
var w = this.dobra.clientWidth, h = this.dobra.clientHeight;
this.w = w; this.h = h;
this.renderer.setSize(w, h, false);
this.camera.right = w; this.camera.top = 0; this.camera.bottom = h; this.camera.left = 0;
this.camera.updateProjectionMatrix();
if (this.montada && this.aoRedimensionar) { this.aoRedimensionar(); }
};
Cena.prototype.laco = function () {
if (!this.rodando || document.hidden) { return; }
var eu = this;
this.passo(0.016);
this.desenhar();
requestAnimationFrame(function () { eu.laco(); });
};
Cena.prototype.desenhar = function () { this.renderer.render(this.scene, this.camera); };
Cena.prototype.passo = function (dt) { if (this.passoFn) { this.passoFn(dt); } };
function iniciar() {
if (!window.THREE) { return; }
Array.prototype.forEach.call(document.querySelectorAll('canvas[data-cena]'), function (cv) {
try { new Cena(cv); }
catch (e) { cv.style.display = 'none'; } // cena que falha some; a página segue
});
}
if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', iniciar); }
else { setTimeout(iniciar, 0); } // dá um tique para os arquivos de cena se registrarem
return {
registrar: function (nome, montar) { cenas[nome] = montar; },
Cena: Cena,
celular: CELULAR,
reduzir: REDUZIR
};
})();
/* ===== leque.js ==================================================================== */
/* PAR-04 · Leque — feixes de um canto que abrem num arco achatado e reagem ao cursor.
É a cena de dobra escura: nasceu sob o manifesto da OCTA, com a cor clara por cima do escuro.
Exige particulas-motor.js antes. data-cena="leque" */
(function () {
'use strict';
function montar() {
var M = this.CELULAR ? 20 : 34;
this.cx = this.w * .86; this.cy = this.h * .8;
this.pontas = [];
var lg = new THREE.BufferGeometry();
lg.setAttribute('position', new THREE.BufferAttribute(new Float32Array(M * 6), 3));
this.linhas = new THREE.LineSegments(lg, new THREE.LineBasicMaterial({ color: this.COR, transparent: true, opacity: .16 }));
this.scene.add(this.linhas);
var pg = new THREE.BufferGeometry();
pg.setAttribute('position', new THREE.BufferAttribute(new Float32Array(M * 3), 3));
this.pts = new THREE.Points(pg, new THREE.PointsMaterial({ color: this.COR, size: 5, transparent: true, opacity: .5, map: this.PONTO, alphaTest: .5 }));
this.scene.add(this.pts);
for (var i = 0; i < M; i++) {
/* o leque abre para a esquerda e para cima, num arco de ~1,05 rad */
var ang = Math.PI + (-.5 + (i / (M - 1))) * 1.05;
this.pontas.push({ ang: ang, len: this.w * (.5 + Math.random() * .42),
ph: Math.random() * 6.28, ox: 0, oy: 0, vox: 0, voy: 0 });
}
var eu = this;
this.passoFn = function (dt) { passo.call(eu, dt); };
this.aoRedimensionar = function () { this.cx = this.w * .86; this.cy = this.h * .8; };
}
function passo(dt) {
this.t += dt;
var lp = this.linhas.geometry.attributes.position.array;
var pp = this.pts.geometry.attributes.position.array;
var abre = 1 + Math.sin(this.t * .3) * .07;
for (var i = 0; i < this.pontas.length; i++) {
var tp = this.pontas[i];
var wob = Math.sin(this.t * .6 + tp.ph) * 7;
/* o y vai a meio comprimento: é o achatamento que faz o leque e não um sol */
var x = this.cx + Math.cos(tp.ang * abre) * tp.len;
var y = this.cy + Math.sin(tp.ang * abre) * tp.len * .5 + wob;
var dx = (x + tp.ox) - this.mouse.x, dy = (y + tp.oy) - this.mouse.y, d = Math.hypot(dx, dy);
if (d < 260 && d > 1) { var f = (1 - d / 260) * 3.2; tp.vox += (dx / d) * f; tp.voy += (dy / d) * f; }
tp.vox += -tp.ox * .04; tp.voy += -tp.oy * .04;
tp.vox *= .88; tp.voy *= .88;
tp.ox += tp.vox; tp.oy += tp.voy;
var tx = x + tp.ox, ty = y + tp.oy;
lp[i * 6] = this.cx; lp[i * 6 + 1] = this.cy; lp[i * 6 + 2] = 0;
lp[i * 6 + 3] = tx; lp[i * 6 + 4] = ty; lp[i * 6 + 5] = 0;
pp[i * 3] = tx; pp[i * 3 + 1] = ty; pp[i * 3 + 2] = 0;
}
this.linhas.geometry.attributes.position.needsUpdate = true;
this.pts.geometry.attributes.position.needsUpdate = true;
}
OctaParticulas.registrar('leque', montar);
})();
/* ===== markup.html ================================================================= */
<!-- PAR-04 · Leque. O <canvas> precisa de um PAI POSICIONADO com altura própria: a cena
mede o pai, não o canvas. three.js vem antes; o motor antes da cena.
data-cor e data-cor-destaque são opcionais (padrão: os do IDV da OCTA). -->
<div class="dobra" style="position:relative;min-height:60vh;overflow:hidden">
<canvas data-cena="leque" data-cor="#ebebeb" aria-hidden="true"
style="position:absolute;inset:0;width:100%;height:100%"></canvas>
<!-- o conteúdo da dobra vai aqui, com position:relative para ficar por cima -->
</div>
<script src="three.min.js"></script>
<script src="particulas-motor.js"></script>
<script src="leque.js"></script>
Já rodou em
- site da proposta ao Pedro (27/08/2026) — a dobra do manifesto, em cor clara sobre fundo escuro
Exige
- three.js (r12x+), carregado antes do motor
Como se configura
data-cena — qual cena montar (obrigatorio)data-cor — a cor dos nos e das linhas (padrao #212121)data-cor-destaque — o acento (padrao #e8ad32)
A ficha
O que o componente entrega
Exige: three.js (r12x+) carregado antes, e particulas-motor.js carregado antes da cena. O <canvas> precisa de um pai posicionado com altura própria — a cena mede o pai, não o canvas.
Três regras de desempenho que vêm do motor, e não são opcionais:
- pausa fora da tela (
IntersectionObservercom 80 px de folga): cena invisível não queima bateria; - DPR no teto de 2: acima disso o ganho é invisível e o custo não;
prefers-reduced-motiondesenha um quadro e para — a cena existe, não se mexe.
A câmera é ortográfica em pixel: x e y da cena são as coordenadas da tela, o que deixa a conta de física legível, sem conversão de espaço no meio do passo.
Detalhes que importam:
- O
yvai a meio comprimento dox: é o achatamento que faz um leque, e não um sol. - Nasceu para dobra escura com a cor clara por cima — o
data-coré o que inverte isso.
O que a adaptação da OCTA mudou
- O motor saiu do arquivo da cena. No site de origem as seis cenas viviam num
motion.jsde 444 linhas; aqui você inclui o motor uma vez e, depois dele, só a cena que for usar. - A cor deixou de ser constante no código e virou
data-cor/data-cor-destaqueno<canvas>. - A cena que falha some em silêncio e a página segue — o erro não derruba a dobra.
Lacunas
- A origem é fixa em 86% × 80% da dobra, sempre abrindo para a esquerda e para cima.
- Em dobra larga demais os feixes não alcançam a borda oposta.