refactor(islands): remove dead offscreen canvas pixel writes from updateField
This commit is contained in:
parent
24db26177e
commit
f8113f7a94
1 changed files with 1 additions and 14 deletions
|
|
@ -93,10 +93,6 @@ export default function ParticleField() {
|
||||||
const reduce = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
const reduce = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
||||||
const cfg = PARTICLE_CONFIG;
|
const cfg = PARTICLE_CONFIG;
|
||||||
|
|
||||||
const off = document.createElement("canvas");
|
|
||||||
off.width = cfg.fieldOffscreenW;
|
|
||||||
off.height = cfg.fieldOffscreenH;
|
|
||||||
const oCtx = off.getContext("2d")!;
|
|
||||||
const fieldCache = new Float32Array(cfg.fieldOffscreenW * cfg.fieldOffscreenH);
|
const fieldCache = new Float32Array(cfg.fieldOffscreenW * cfg.fieldOffscreenH);
|
||||||
|
|
||||||
const P = buildPermutation();
|
const P = buildPermutation();
|
||||||
|
|
@ -147,21 +143,12 @@ export default function ParticleField() {
|
||||||
const scale = fieldScale * 0.0018;
|
const scale = fieldScale * 0.0018;
|
||||||
const ox = elapsed * timeConstantX;
|
const ox = elapsed * timeConstantX;
|
||||||
const oy = elapsed * timeConstantY;
|
const oy = elapsed * timeConstantY;
|
||||||
const imgData = oCtx.createImageData(oW, oH);
|
|
||||||
const d = imgData.data;
|
|
||||||
for (let py = 0; py < oH; py++) {
|
for (let py = 0; py < oH; py++) {
|
||||||
for (let px = 0; px < oW; px++) {
|
for (let px = 0; px < oW; px++) {
|
||||||
const raw = fbm(P, px * scale + ox, py * scale + oy, fieldOctaves);
|
const raw = fbm(P, px * scale + ox, py * scale + oy, fieldOctaves);
|
||||||
const v = Math.max(0, Math.min(1, raw * 1.8 + 0.5));
|
fieldCache[py * oW + px] = Math.max(0, Math.min(1, raw * 1.8 + 0.5));
|
||||||
fieldCache[py * oW + px] = v;
|
|
||||||
const idx = (py * oW + px) * 4;
|
|
||||||
d[idx] = Math.round(v * 30 + (1 - v) * 5);
|
|
||||||
d[idx + 1] = Math.round(v * 110 + (1 - v) * 18);
|
|
||||||
d[idx + 2] = Math.round(v * 210 + (1 - v) * 55);
|
|
||||||
d[idx + 3] = 255;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
oCtx.putImageData(imgData, 0, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function draw() {
|
function draw() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue