48

Sine field

idle
18 lines · vanilla
view source
function tick({ ctx, frame, width, height }) {
  const img = ctx.createImageData(width, height);
  const data = img.data;
  const t = frame * 0.02;
  for (let y = 0; y < height; y += 2) {
    for (let x = 0; x < width; x += 2) {
      const v = Math.sin(x * 0.02 + t) + Math.sin(y * 0.025 - t * 1.3) + Math.sin((x + y) * 0.015 + t * 0.7);
      const i = (y * width + x) * 4;
      const c = Math.floor(128 + v * 60);
      data[i] = c >> 1;
      data[i+1] = c;
      data[i+2] = 255 - c;
      data[i+3] = 255;
    }
  }
  ctx.putImageData(img, 0, 0);
}
function init() {}

Comments (0)

Log in to comment.