Spacetime Curvature & Geodesics
3D Flamm's paraboloid embedding visualization of curved 4D spacetime around a massive central body. Demonstrates Schwarzschild metric curvature funneling, stable orbital geodesics, and gravitational light ray deflection angles (Δφ ≈ 4GM/c²b).
60 FPS • Canvas 2D
Click + Drag to interact with field
</>
Full Executable Algorithm Code
156 lines
6190 chars
// 061 - Spacetime Curvature & Geodesics (physics)
// 1:1 Original algorithm engine source
function createSpacetimeCurvature() {
const GRID_RADIAL = 22;
const GRID_ANGULAR = 32;
const photons = [
{ startY: -120, speed: 180 },
{ startY: -75, speed: 180 },
{ startY: -45, speed: 180 },
{ startY: 45, speed: 180 },
{ startY: 75, speed: 180 },
{ startY: 120, speed: 180 }
];
return {
setup() {
},
render(context, timeState, params) {
const { ctx, width, height } = context;
const massStrength = Number(params.massDensity || 1.2);
const t = timeState.time;
ctx.fillStyle = "#010205";
ctx.fillRect(0, 0, width, height);
const cx = width * 0.5;
const cy = height * 0.52;
const scale = Math.min(width, height) / 480;
const rotY = t * 0.15;
const rotX = 0.65;
const rotZ = 0;
ctx.save();
ctx.globalCompositeOperation = "screen";
const maxR = 210 * scale;
const rs = 28 * massStrength * scale;
function getSpacetimeDepth(r) {
if (r < rs) return 130 * scale;
return 130 * scale - 2 * Math.sqrt(Math.max(0, rs * (r - rs))) * 4.2;
}
for (let r = 1; r <= GRID_RADIAL; r++) {
const normR = r / GRID_RADIAL;
const curR = rs + Math.pow(normR, 1.4) * (maxR - rs);
const depthZ = getSpacetimeDepth(curR);
ctx.beginPath();
for (let a = 0; a <= GRID_ANGULAR; a++) {
const phi = a / GRID_ANGULAR * Math.PI * 2;
const px = curR * Math.cos(phi);
const py = curR * Math.sin(phi);
const proj = project3D(px, depthZ, py, rotX, rotY, rotZ, cx, cy, 450, 520);
if (a === 0) ctx.moveTo(proj.x, proj.y);
else ctx.lineTo(proj.x, proj.y);
}
ctx.closePath();
const ringHue = (200 + normR * 45) % 360;
ctx.strokeStyle = hsla(ringHue, 90, 68, 0.08 + (1 - normR) * 0.45);
ctx.lineWidth = r === 1 ? 2 : 1;
ctx.stroke();
}
for (let a = 0; a < GRID_ANGULAR; a += 2) {
const phi = a / GRID_ANGULAR * Math.PI * 2;
ctx.beginPath();
for (let r = 1; r <= GRID_RADIAL; r++) {
const normR = r / GRID_RADIAL;
const curR = rs + Math.pow(normR, 1.4) * (maxR - rs);
const depthZ = getSpacetimeDepth(curR);
const px = curR * Math.cos(phi);
const py = curR * Math.sin(phi);
const proj = project3D(px, depthZ, py, rotX, rotY, rotZ, cx, cy, 450, 520);
if (r === 1) ctx.moveTo(proj.x, proj.y);
else ctx.lineTo(proj.x, proj.y);
}
ctx.strokeStyle = "rgba(56, 189, 248, 0.2)";
ctx.lineWidth = 1;
ctx.stroke();
}
const pSingularity = project3D(0, 130 * scale, 0, rotX, rotY, rotZ, cx, cy, 450, 520);
const massGrad = ctx.createRadialGradient(pSingularity.x, pSingularity.y, 2, pSingularity.x, pSingularity.y, 24 * scale);
massGrad.addColorStop(0, "#ffffff");
massGrad.addColorStop(0.3, "#f59e0b");
massGrad.addColorStop(0.7, "#ea580c");
massGrad.addColorStop(1, "rgba(234, 88, 12, 0)");
ctx.fillStyle = massGrad;
ctx.beginPath();
ctx.arc(pSingularity.x, pSingularity.y, 24 * scale, 0, Math.PI * 2);
ctx.fill();
const orbitTheta = t * 1.8;
const orbitR = 95 * scale;
const orbitZ = getSpacetimeDepth(orbitR);
const pOrb = project3D(orbitR * Math.cos(orbitTheta), orbitZ, orbitR * Math.sin(orbitTheta), rotX, rotY, rotZ, cx, cy, 450, 520);
ctx.fillStyle = "#38bdf8";
ctx.shadowColor = "#38bdf8";
ctx.shadowBlur = 12;
ctx.beginPath();
ctx.arc(pOrb.x, pOrb.y, 5 * scale, 0, Math.PI * 2);
ctx.fill();
ctx.shadowBlur = 0;
for (let p = 0; p < photons.length; p++) {
const ph = photons[p];
ctx.beginPath();
const steps = 40;
for (let i = 0; i <= steps; i++) {
const normX = (i / steps - 0.5) * (maxR * 2.2);
const impactB = ph.startY * scale;
const dist = Math.hypot(normX, impactB);
const defAmount = 4 * rs / (dist + rs * 0.5);
const yDef = impactB + Math.sign(impactB) * defAmount * (normX > 0 ? 1 : -1) * 8;
const zDepth = getSpacetimeDepth(Math.max(rs + 5, dist));
const proj = project3D(normX, zDepth, yDef, rotX, rotY, rotZ, cx, cy, 450, 520);
if (i === 0) ctx.moveTo(proj.x, proj.y);
else ctx.lineTo(proj.x, proj.y);
}
ctx.strokeStyle = "#fbbf24";
ctx.lineWidth = 1.4;
ctx.stroke();
}
ctx.restore();
ctx.save();
ctx.font = "11px monospace";
ctx.fillStyle = "rgba(56, 189, 248, 0.9)";
ctx.fillText(`General Relativity \u2014 Spacetime Curvature & Geodesics`, 20, 28);
ctx.fillStyle = "#94a3b8";
ctx.fillText(`G_\u03BC\u03BD = (8\u03C0G/c\u2074) T_\u03BC\u03BD | Schwarzschild Metric: ds\xB2 = -(1-r_s/r)c\xB2dt\xB2 + (1-r_s/r)\u207B\xB9dr\xB2 + r\xB2d\u03A9\xB2`, 20, 44);
ctx.fillText(`Gravitational Lensing Deflection: \u0394\u03C6 \u2248 4GM/(c\xB2b) | Photon Null Geodesics [Gold]`, 20, 60);
ctx.restore();
}
};
}
// Default parameters from content metadata
const defaultParams = [
{
"key": "massDensity",
"label": "Central Mass (M)",
"type": "range",
"min": 0.5,
"max": 2.5,
"step": 0.1,
"defaultValue": 1.2,
"description": "Mass determining Schwarzschild radius r_s = 2GM/c²"
}
];
if (!window.__art_instances) window.__art_instances = {};
if (!window.__art_instances['spacetime-curvature-geodesic']) {
const inst = typeof createSpacetimeCurvature === 'function' ? createSpacetimeCurvature() : null;
if (inst && inst.setup) {
inst.setup({ ctx, width, height, dpr: 1, aspectRatio: width / height }, defaultParams);
}
window.__art_instances['spacetime-curvature-geodesic'] = inst;
}
const instance = window.__art_instances['spacetime-curvature-geodesic'];
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
Gμν=c48πGTμν,ds2=−(1−rrs)c2dt2+(1−rrs)−1dr2+r2dΩ2
Click to expand
∑
Spacetime Curvature & Geodesics
Full Mathematical System • physics
100%
Complete System of Equations
[Governing Law][Discrete Progression][Domain & Space][Parameter State]Gμν=c48πGTμν,ds2=−(1−rrs)c2dt2+(1−rrs)−1dr2+r2dΩ2z(r)=2⋅rs⋅(r−rs);defAngle=(4⋅GM)/(c2⋅b);x∈R2,t∈R+,ω∈[0,2π]λmassDensity=1.2(Central Mass (M))
Gμν=c48πGTμν,ds2=−(1−rrs)c2dt2+(1−rrs)−1dr2+r2dΩ2
Computational Implementation (JavaScript Engine Equivalent)
z(r) = 2 * Math.sqrt(rs * (r - rs)); defAngle = (4 * GM) / (c^2 * b); Compact Formula
z(r) = 2 * Math.sqrt(rs * (r - rs)); defAngle = (4 * GM) / (c^2 * b); Mathematical Tags
#general-relativity
#einstein-field-equations
#spacetime-curvature
#geodesics
#gravitational-lensing
#physics-study
Author: Relativity Core Target: 60 FPS
Press ESC or F to exit