// 007 - Smoke Lattice Drift (fluid)
// 1:1 Original algorithm engine source
function createSmokeLattice() {
const GRID_SIZE = 40;
const density = new Float32Array(GRID_SIZE * GRID_SIZE);
return {
setup() {
density.fill(0);
},
render(context, timeState, params) {
const { ctx, width, height } = context;
const t = timeState.time * Number(params.speed || 1);
const cellW = width / GRID_SIZE;
const cellH = height / GRID_SIZE;
ctx.fillStyle = "#08090d";
ctx.fillRect(0, 0, width, height);
const cx = GRID_SIZE / 2;
const cy = GRID_SIZE / 2;
for (let y = 1; y < GRID_SIZE - 1; y++) {
for (let x = 1; x < GRID_SIZE - 1; x++) {
const idx = y * GRID_SIZE + x;
const dx = x - cx;
const dy = y - cy;
const dist = Math.sqrt(dx * dx + dy * dy);
const injection = Math.sin(dist * 0.4 - t * 3) * Math.cos(Math.atan2(dy, dx) * 4 + t * 2) * Math.exp(-dist * 0.1);
density[idx] = Math.max(0, Math.min(1, density[idx] * 0.94 + injection * 0.15));
if (density[idx] > 0.02) {
const px = x * cellW;
const py = y * cellH;
const alpha = density[idx];
const hue = (240 + alpha * 100 + t * 20) % 360;
ctx.fillStyle = hsla(hue, 80, 60, alpha * 0.8);
ctx.beginPath();
ctx.arc(px + cellW * 0.5, py + cellH * 0.5, cellW * 0.7 * alpha, 0, Math.PI * 2);
ctx.fill();
}
}
}
}
};
}
// Default parameters from content metadata
const defaultParams = [
{
"key": "speed",
"label": "Emission Speed",
"type": "range",
"min": 0.3,
"max": 3,
"step": 0.1,
"defaultValue": 1,
"description": "Turbulence oscillation rate"
}
];
if (!window.__art_instances) window.__art_instances = {};
if (!window.__art_instances['smoke-lattice']) {
const inst = typeof createSmokeLattice === 'function' ? createSmokeLattice() : null;
if (inst && inst.setup) {
inst.setup({ ctx, width, height, dpr: 1, aspectRatio: width / height }, defaultParams);
}
window.__art_instances['smoke-lattice'] = inst;
}
const instance = window.__art_instances['smoke-lattice'];
if (instance && instance.render) {
instance.render(
{ ctx, width, height, dpr: 1, aspectRatio: width / height },
{ time, deltaTime: dt, frameCount: Math.floor(time * 60), fps: 60 },
defaultParams
);
}