228

Black Hole Lensing

General relativistic gravitational ray-tracing showing the extreme light bending, photon sphere ring, and Doppler-beamed accretion disk.

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

Full Executable Algorithm Code

// 021 - Black Hole Lensing (space)
// 1:1 Original algorithm engine source
function createBlackHoleLensing() {
  const PARTICLES = 2200;
  const rad = new Float32Array(PARTICLES);
  const ang = new Float32Array(PARTICLES);
  const speed = new Float32Array(PARTICLES);
  return {
    setup() {
      for (let i = 0; i < PARTICLES; i++) {
        rad[i] = 40 + Math.random() * 160;
        ang[i] = Math.random() * Math.PI * 2;
        speed[i] = 2.5 / Math.sqrt(rad[i]);
      }
    },
    render(context, _timeState, params) {
      const { ctx, width, height } = context;
      const rs = Number(params.schwarzschildRadius || 36);
      const cx = width * 0.5;
      const cy = height * 0.5;
      ctx.fillStyle = "rgba(8, 9, 13, 0.25)";
      ctx.fillRect(0, 0, width, height);
      for (let i = 0; i < PARTICLES; i++) {
        ang[i] += speed[i] * 0.04;
        const inclination = 0.45;
        const rawX = Math.cos(ang[i]) * rad[i];
        const rawY = Math.sin(ang[i]) * rad[i] * inclination;
        const d = Math.sqrt(rawX * rawX + rawY * rawY);
        let warpedX = rawX;
        let warpedY = rawY;
        if (d > rs && rawY < 0) {
          const bend = rs * 1.5 / d;
          warpedY = rawY - bend * 22;
        }
        const px = cx + warpedX;
        const py = cy + warpedY;
        const doppler = Math.sin(ang[i]);
        const hue = doppler > 0 ? 190 + doppler * 30 : 25 + Math.abs(doppler) * 20;
        const alpha = Math.min(1, Math.max(0.1, (1 + doppler * 0.6) * (1 - rad[i] / 220)));
        ctx.fillStyle = hsla(hue, 95, 65, alpha);
        ctx.fillRect(px, py, 1.8, 1.8);
      }
      ctx.beginPath();
      ctx.arc(cx, cy, rs * 1.5, 0, Math.PI * 2);
      ctx.strokeStyle = "rgba(56, 189, 248, 0.4)";
      ctx.lineWidth = 2;
      ctx.stroke();
      ctx.fillStyle = "#050608";
      ctx.beginPath();
      ctx.arc(cx, cy, rs, 0, Math.PI * 2);
      ctx.fill();
      ctx.strokeStyle = "rgba(255, 255, 255, 0.8)";
      ctx.lineWidth = 1;
      ctx.stroke();
    }
  };
}

// Default parameters from content metadata
const defaultParams = [
  {
    "key": "schwarzschildRadius",
    "label": "Schwarzschild Radius (rs)",
    "type": "range",
    "min": 15,
    "max": 60,
    "step": 1,
    "defaultValue": 36,
    "description": "Event horizon radius"
  }
];

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

const instance = window.__art_instances['black-hole-lensing'];
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

high
Analytical Equation
α^=4GMc2b=2rsb,rs=2GMc2,Iobs=Iemitδ4\hat{\alpha} = \frac{4GM}{c^2 b} = \frac{2 r_s}{b}, \quad r_s = \frac{2GM}{c^2}, \quad I_{\text{obs}} = I_{\text{emit}} \cdot \delta^4
Click to expand
Compact Formula
v_orb = 2.5 / √r, y_warp = y - (1.5*rs / d)*22, doppler_hue = 190 + 30*sin(θ)

Mathematical Tags

#black-hole #general-relativity #lensing #astrophysics #space #gravity
Author: Math Art Core Target: 60 FPS

Export & Embed: Black Hole Lensing

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/black-hole-lensing" 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! ✨