Prototype lightning, twinkle and firefly particles in the visual lab
The Particles tab of the visual lab now previews three persistent particle animations for mythic cards, drawn on a canvas inside the illustration or over the whole card. Lightning bolts grow from the edges towards a random point near the hero and pass behind a cut-out hero with the prismatic parallax. Twinkles pop chosen motifs in and out with a light cross at their peak. Fireflies drift on winding paths, pulse and move away from the pointer. Each animation offers a palette, a zone and its own sliders, runs only on a large or hovered card, and stays still under reduced motion. Nothing is saved on the variations yet. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
9f70bea523
commit
f77a0ca577
15 changed files with 1779 additions and 16 deletions
152
website/src/features/cards/flareSprites.js
Normal file
152
website/src/features/cards/flareSprites.js
Normal file
|
|
@ -0,0 +1,152 @@
|
|||
// Rôle : sprites des motifs de particules persistantes (scintillements, lucioles) : silhouettes procédurales de rayon 1,
|
||||
// rendues une fois par couleur avec halo et cœur clair, puis seulement recopiées à chaque image.
|
||||
const TAU = Math.PI * 2;
|
||||
export const SPRITE_SIZE = 96;
|
||||
|
||||
// Angle d'affichage d'un motif. La bulle ne tourne jamais : son reflet reste en haut à droite, comme la lumière qui
|
||||
// l'éclaire. Le cœur reste à l'endroit, à peine incliné. Les autres motifs prennent l'angle libre qu'on leur donne.
|
||||
export function motifAngle(motifId, angle) {
|
||||
if (motifId === "bubble") return 0;
|
||||
if (motifId === "heart") return Math.sin(angle) * 0.25;
|
||||
return angle;
|
||||
}
|
||||
|
||||
// Silhouette d'un motif centrée sur l'origine, de rayon 1 ; `stroke` pour les motifs en traits.
|
||||
function motifPath(context, motifId) {
|
||||
context.beginPath();
|
||||
if (motifId === "four-point-star" || motifId === "glint") {
|
||||
const k = motifId === "glint" ? 0.06 : 0.16;
|
||||
context.moveTo(0, -1);
|
||||
context.quadraticCurveTo(k, -k, 1, 0);
|
||||
context.quadraticCurveTo(k, k, 0, 1);
|
||||
context.quadraticCurveTo(-k, k, -1, 0);
|
||||
context.quadraticCurveTo(-k, -k, 0, -1);
|
||||
} else if (motifId === "star") {
|
||||
for (let index = 0; index < 10; index++) {
|
||||
const radius = index % 2 ? 0.45 : 1;
|
||||
const angle = -Math.PI / 2 + (index * Math.PI) / 5;
|
||||
context.lineTo(Math.cos(angle) * radius, Math.sin(angle) * radius);
|
||||
}
|
||||
context.closePath();
|
||||
} else if (motifId === "diamond") {
|
||||
context.moveTo(0, -1);
|
||||
context.lineTo(0.62, 0);
|
||||
context.lineTo(0, 1);
|
||||
context.lineTo(-0.62, 0);
|
||||
context.closePath();
|
||||
} else if (motifId === "heart") {
|
||||
context.moveTo(0, 0.9);
|
||||
context.bezierCurveTo(-1.1, 0.1, -0.85, -0.85, 0, -0.35);
|
||||
context.bezierCurveTo(0.85, -0.85, 1.1, 0.1, 0, 0.9);
|
||||
} else if (motifId === "snowflake") {
|
||||
for (let arm = 0; arm < 6; arm++) {
|
||||
const angle = (arm * Math.PI) / 3;
|
||||
const point = (radius, offset = 0) => [Math.cos(angle + offset) * radius, Math.sin(angle + offset) * radius];
|
||||
context.moveTo(0, 0);
|
||||
context.lineTo(...point(1));
|
||||
context.moveTo(...point(0.55));
|
||||
context.lineTo(...point(0.8, 0.32));
|
||||
context.moveTo(...point(0.55));
|
||||
context.lineTo(...point(0.8, -0.32));
|
||||
}
|
||||
} else if (motifId === "firefly") {
|
||||
context.arc(0, 0, 0.55, 0, TAU);
|
||||
} else {
|
||||
context.arc(0, 0, 1, 0, TAU);
|
||||
}
|
||||
}
|
||||
|
||||
// Bulle : une sphère translucide (voile coloré et contour lumineux) avec son reflet clair décalé en haut à droite, aux
|
||||
// bords à peine adoucis par un dégradé (un filtre de flou n'est pas pris en charge partout sur un canvas).
|
||||
function bubble(context, radius, color, core) {
|
||||
context.save();
|
||||
context.scale(radius, radius);
|
||||
context.beginPath();
|
||||
context.arc(0, 0, 1, 0, TAU);
|
||||
context.globalAlpha = 0.28;
|
||||
context.fillStyle = color;
|
||||
context.fill();
|
||||
context.globalAlpha = 1;
|
||||
context.lineWidth = 0.09;
|
||||
context.strokeStyle = color;
|
||||
context.shadowColor = color;
|
||||
context.shadowBlur = 6;
|
||||
context.stroke();
|
||||
context.shadowBlur = 0;
|
||||
const highlight = context.createRadialGradient(0.36, -0.36, 0, 0.36, -0.36, 0.3);
|
||||
highlight.addColorStop(0, core);
|
||||
highlight.addColorStop(0.75, core);
|
||||
highlight.addColorStop(1, "transparent");
|
||||
context.globalAlpha = 0.9;
|
||||
context.fillStyle = highlight;
|
||||
context.beginPath();
|
||||
context.arc(0.36, -0.36, 0.3, 0, TAU);
|
||||
context.fill();
|
||||
context.restore();
|
||||
}
|
||||
|
||||
// Sprite d'un motif dans une couleur : halo, silhouette colorée lumineuse, puis cœur clair. Rendu une seule fois (le flou y
|
||||
// est permis), puis seulement recopié à chaque image.
|
||||
export function motifSprite(motifId, color, core) {
|
||||
const canvas = document.createElement("canvas");
|
||||
canvas.width = SPRITE_SIZE;
|
||||
canvas.height = SPRITE_SIZE;
|
||||
const context = canvas.getContext("2d");
|
||||
const half = SPRITE_SIZE / 2;
|
||||
const halo = context.createRadialGradient(half, half, 0, half, half, half);
|
||||
halo.addColorStop(0, color);
|
||||
halo.addColorStop(0.2, color);
|
||||
// La luciole rayonne plus loin que les motifs dessinés.
|
||||
halo.addColorStop(motifId === "firefly" ? 1 : 0.75, "transparent");
|
||||
// La luciole est surtout un halo : petit cœur, large lueur.
|
||||
context.globalAlpha = motifId === "bubble" ? 0.3 : motifId === "firefly" ? 0.8 : 0.55;
|
||||
context.fillStyle = halo;
|
||||
context.fillRect(0, 0, SPRITE_SIZE, SPRITE_SIZE);
|
||||
context.globalAlpha = 1;
|
||||
context.translate(half, half);
|
||||
if (motifId === "bubble") {
|
||||
bubble(context, half * 0.34, color, core);
|
||||
return canvas;
|
||||
}
|
||||
const stroked = motifId === "snowflake";
|
||||
for (const [scale, style, blur, width] of [[0.34, color, 10, 0.16], [0.2, core, 4, 0.1]]) {
|
||||
context.save();
|
||||
context.scale(half * scale, half * scale);
|
||||
context.shadowColor = color;
|
||||
context.shadowBlur = blur;
|
||||
motifPath(context, motifId);
|
||||
if (stroked) {
|
||||
context.lineCap = "round";
|
||||
context.lineWidth = width;
|
||||
context.strokeStyle = style;
|
||||
context.stroke();
|
||||
} else {
|
||||
context.fillStyle = style;
|
||||
context.fill();
|
||||
}
|
||||
context.restore();
|
||||
}
|
||||
return canvas;
|
||||
}
|
||||
|
||||
// Éclat en croix de l'apogée : deux traits fins dégradés, clairs au centre.
|
||||
export function streakSprite(color, core) {
|
||||
const canvas = document.createElement("canvas");
|
||||
canvas.width = SPRITE_SIZE * 2;
|
||||
canvas.height = SPRITE_SIZE * 2;
|
||||
const context = canvas.getContext("2d");
|
||||
const size = SPRITE_SIZE * 2;
|
||||
for (const vertical of [false, true]) {
|
||||
const gradient = vertical ? context.createLinearGradient(0, 0, 0, size) : context.createLinearGradient(0, 0, size, 0);
|
||||
gradient.addColorStop(0, "transparent");
|
||||
gradient.addColorStop(0.4, color);
|
||||
gradient.addColorStop(0.5, core);
|
||||
gradient.addColorStop(0.6, color);
|
||||
gradient.addColorStop(1, "transparent");
|
||||
context.fillStyle = gradient;
|
||||
const thickness = vertical ? 4 : 5;
|
||||
if (vertical) context.fillRect(size / 2 - thickness / 2, size * 0.18, thickness, size * 0.64);
|
||||
else context.fillRect(0, size / 2 - thickness / 2, size, thickness);
|
||||
}
|
||||
return canvas;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue