438

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


import type { ArtRenderer, ParameterState, RenderContext, TimeState } from '../../types/engine';
import { hsla } from '../common/color';

// Schwarzschild gravitational light deflection & relativistic accretion disk
export function createBlackHoleLensing(): ArtRenderer {
  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;
        // Keplerian orbital speed v ~ 1/sqrt(r)
        speed[i] = 2.5 / Math.sqrt(rad[i]);
      }
    },

    render(context: RenderContext, _timeState: TimeState, params: ParameterState) {
      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);

      // Accretion disk particles
      for (let i = 0; i < PARTICLES; i++) {
        ang[i] += speed[i] * 0.04;

        // Relativistic disk inclination & gravitational lensing warping
        const inclination = 0.45;
        const rawX = Math.cos(ang[i]) * rad[i];
        const rawY = Math.sin(ang[i]) * rad[i] * inclination;

        // Lensing bending: light rays bent around photon sphere
        const d = Math.sqrt(rawX * rawX + rawY * rawY);
        let warpedX = rawX;
        let warpedY = rawY;

        if (d > rs && rawY < 0) {
          // Einstein ring upper projection
          const bend = (rs * 1.5) / d;
          warpedY = rawY - bend * 22;
        }

        const px = cx + warpedX;
        const py = cy + warpedY;

        // Relativistic Doppler beaming (approaching side is brighter/bluer)
        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);
      }

      // Event Horizon & Photon Sphere Glow
      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();

      // Absolute Event Horizon shadow
      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();
    },
  };
}
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
113 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! ✨