function* run(options = {}) {
const {
width: w = 800,
height: h = h,
resolution: res = 1/4,
noiseScale: s = .6,
layers: count = 4,
lower = 1,
upper = 0,
tx = 0,
ty = 0,
tz = 0,
sxy = 0,
sz = 0,
colorLow = '#000',
colorHigh = '#fff',
colorBg = '#000',
gco = 'source-over',
seed = '0'
} = options;
const simplex = new noise('0');
const ws = w*res|0, hs = h*res|0;
const color = d3.interpolateHsl(colorLow, colorHigh);
const layers = Array(count).fill()
.map((v,i,a)=>i/(a.length-1))
.map(t => layer(ws, hs, color2rgba(color(t))));
const spotLayer = layer(ws, hs, color2rgba('#0000FF'))
const cOut = canvas.getContext('2d');
cOut.globalCompositeOperation = gco;
const bgFill = new ImageData(w, h);
{
const bg = color2rgba(colorBg);
for(let i=0; i<bgFill.data.length; i+=4) bgFill.data.set(bg, i);
}
while (playing) { // Reactively checks if checkbox is true
let t = 0;
cOut.putImageData(bgFill, 0, 0);
layers.map((l,i) => {
const lt = i/layers.length;
const u = (x, y) => smoothstep(
scaleY2(sigmoid(normScaleX(y))), scaleY(sigmoid(normScaleX(y))),
// simplex.noise3D(x*s, y*s, lt*s) ** 2
simplex.noise3D(x*s + t*tx, y*s + t*ty, lt*s*sz + t*tz) ** 2
);
const p = (lt ** 2) * c;
// const p = 0
cOut.drawImage(l.update(u), 0, 0, ws, hs, -p, -p, w+p*2, h+p*2);
});
// const u = (x, y) => smoothstep(
// spotScale(y), spotScale(y),
// simplex.noise3D(x*s, y*s, spotLayerDepth*s) ** 2
// // simplex.noise3D(x*s + t*tx, y*s + t*ty, lt*s*sz + t*tz) ** 2
// );
// const p = 100
// cOut.drawImage(spotLayer.update(u), 0, 0, ws, hs, -p, -p, w+p*2, h+p*2);
// Draw dashed horizontal line at y = 150
cOut.beginPath();
cOut.setLineDash([3, 1]); // Define dashes: 10px dash, 5px gap
cOut.moveTo(0, 150); // Start of the line at the left edge of the canvas
cOut.lineTo(cOut.canvas.width, 150); // End of the line at the right edge of the canvas
cOut.strokeStyle = "grey"; // Optional: Set the line color
cOut.lineWidth = 2; // Optional: Set the line width
cOut.stroke();
cOut.setLineDash([]); // Reset to solid lines after the dashed line is drawn
yield cOut.canvas;
updateCanvas2()
t += 1/30;
}
}