228

Rainstorm Precipitation

Meteorological atmospheric downpour integrating aerodynamic terminal velocity fall rates, aerodynamic wind shear slant, and damped Bessel ground collision ripples.

Playground
60 FPS Canvas 2D
Click + Drag to interact with field
</>

Full Executable Algorithm Code

// 041 - Rainstorm Precipitation (fluid)
// 1:1 Original algorithm engine source
function createRainEffect() {
  const MAX_DROPS = 600;
  const MAX_RIPPLES = 48;
  const dropX = new Float32Array(MAX_DROPS);
  const dropY = new Float32Array(MAX_DROPS);
  const dropSpeed = new Float32Array(MAX_DROPS);
  const dropLength = new Float32Array(MAX_DROPS);
  const ripX = new Float32Array(MAX_RIPPLES);
  const ripY = new Float32Array(MAX_RIPPLES);
  const ripRadius = new Float32Array(MAX_RIPPLES);
  const ripLife = new Float32Array(MAX_RIPPLES);
  let nextRipIdx = 0;
  return {
    setup(context) {
      for (let i = 0; i < MAX_DROPS; i++) {
        dropX[i] = Math.random() * context.width;
        dropY[i] = Math.random() * context.height;
        dropSpeed[i] = 400 + Math.random() * 500;
        dropLength[i] = 12 + Math.random() * 18;
      }
      ripLife.fill(-1);
    },
    render(context, timeState, params) {
      const { ctx, width, height } = context;
      const intensity = Number(params.rainDensity || 450);
      const windAngle = Number(params.windShear || 0.15);
      const dt = Math.min(timeState.deltaTime, 0.05);
      const groundY = height * 0.88;
      ctx.fillStyle = "rgba(4, 6, 12, 0.25)";
      ctx.fillRect(0, 0, width, height);
      const activeCount = Math.min(MAX_DROPS, intensity);
      const windDx = Math.sin(windAngle);
      const windDy = Math.cos(windAngle);
      for (let i = 0; i < activeCount; i++) {
        dropY[i] += dropSpeed[i] * dt;
        dropX[i] += dropSpeed[i] * windDx * dt;
        if (dropY[i] >= groundY) {
          dropY[i] = 0;
          dropX[i] = Math.random() * (width + 200) - 100;
          ripX[nextRipIdx] = dropX[i];
          ripY[nextRipIdx] = groundY + (Math.random() - 0.5) * 20;
          ripRadius[nextRipIdx] = 2;
          ripLife[nextRipIdx] = 1;
          nextRipIdx = (nextRipIdx + 1) % MAX_RIPPLES;
        }
        const headX = dropX[i];
        const headY = dropY[i];
        const tailX = headX - windDx * dropLength[i];
        const tailY = headY - windDy * dropLength[i];
        ctx.beginPath();
        ctx.moveTo(tailX, tailY);
        ctx.lineTo(headX, headY);
        ctx.strokeStyle = "rgba(186, 230, 253, 0.55)";
        ctx.lineWidth = 1.1;
        ctx.stroke();
      }
      for (let r = 0; r < MAX_RIPPLES; r++) {
        if (ripLife[r] > 0) {
          ripLife[r] -= dt * 2.2;
          ripRadius[r] += dt * 45;
          ctx.beginPath();
          ctx.ellipse(ripX[r], ripY[r], ripRadius[r], ripRadius[r] * 0.35, 0, 0, Math.PI * 2);
          ctx.strokeStyle = hsla(195, 90, 75, ripLife[r] * 0.7);
          ctx.lineWidth = 1.2;
          ctx.stroke();
        }
      }
      ctx.fillStyle = "rgba(56, 189, 248, 0.04)";
      ctx.fillRect(0, groundY - 15, width, height - groundY + 15);
    }
  };
}

// Default parameters from content metadata
const defaultParams = [
  {
    "key": "rainDensity",
    "label": "Rainfall Intensity",
    "type": "range",
    "min": 100,
    "max": 600,
    "step": 20,
    "defaultValue": 450,
    "description": "Active precipitation streak count"
  },
  {
    "key": "windShear",
    "label": "Wind Shear Slant",
    "type": "range",
    "min": -0.5,
    "max": 0.5,
    "step": 0.05,
    "defaultValue": 0.15,
    "description": "Horizontal gale deflection angle"
  }
];

if (!window.__art_instances) window.__art_instances = {};
if (!window.__art_instances['rain-effect']) {
  const inst = typeof createRainEffect === 'function' ? createRainEffect() : null;
  if (inst && inst.setup) {
    inst.setup({ ctx, width, height, dpr: 1, aspectRatio: width / height }, defaultParams);
  }
  window.__art_instances['rain-effect'] = inst;
}

const instance = window.__art_instances['rain-effect'];
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
  );
}
Edit in Interactive Playground Zero Dependencies • Standalone Canvas 2D
ƒ

Mathematical Formulation

medium
Analytical Equation
vterm=2mgρACd,v=vterm[sinθwindcosθwind],rripple(t)=vwave(ttimpact)v_{\text{term}} = \sqrt{\frac{2 m g}{\rho A C_d}}, \quad \mathbf{v} = v_{\text{term}} \begin{bmatrix} \sin\theta_{\text{wind}} \\ \cos\theta_{\text{wind}} \end{bmatrix}, \quad r_{\text{ripple}}(t) = v_{\text{wave}} (t - t_{\text{impact}})
Click to expand
Compact Formula
y += speed * dt, x += speed * sin(wind) * dt, ripple = ellipse(x, y, r, 0.35r) * exp(-γt)

Mathematical Tags

#rain #precipitation #weather #fluid #ripples #atmosphere #water
Author: Math Art Core Target: 60 FPS

Export & Embed: Rainstorm Precipitation

4K PNG Snapshot

High-resolution single frame render

WebM Video (5s Loop)

60 FPS browser-captured stream

Standalone JS Script

Complete executable Canvas 2D algorithm

HTML Iframe Embed

<iframe src="https://art.fazleyrabbi.xyz/embed/rain-effect" width="500" height="500" frameborder="0" loading="lazy"></iframe>
ESC
↑↓ Navigate Select
110 Mathematical Artworks
Made by Fazley Rabbi

Support the Project

Keep mathematical creative coding alive & open source

Or via Direct Payoneer ($0 Fee)
Payoneer Customer ID: $0 Fee Direct
24076084

💡 Payoneer app: Go to Pay → Pay to recipient → Enter ID 24076084.

Thank you for supporting generative mathematical animations! ✨