Spiral Galaxy Density
Chia-Chiao Lin and Frank Shu's stellar density wave model explaining long-lived spiral arm patterns through quasi-stationary compression waves.
60 FPS • Canvas 2D
Click + Drag to interact with field
</>
Full Executable Algorithm Code
100 lines
3362 chars
// 023 - Spiral Galaxy Density (space)
// 1:1 Original algorithm engine source
function createGalaxySpiralDensity() {
const STARS = 2500;
const starR = new Float32Array(STARS);
const starTheta = new Float32Array(STARS);
const starSpeed = new Float32Array(STARS);
return {
setup() {
for (let i = 0; i < STARS; i++) {
starR[i] = Math.pow(Math.random(), 1.6) * 220 + 8;
starTheta[i] = Math.random() * Math.PI * 2;
starSpeed[i] = 0.8 + 0.2 * (starR[i] / 220);
}
},
render(context, timeState, params) {
const { ctx, width, height } = context;
const t = timeState.time * Number(params.speed || 0.6);
const arms = Number(params.armCount || 2);
const pitch = Number(params.pitchAngle || 0.22);
const scale = Math.min(width, height) / 500;
ctx.fillStyle = "rgba(8, 9, 13, 0.2)";
ctx.fillRect(0, 0, width, height);
const cx = width * 0.5;
const cy = height * 0.5;
ctx.fillStyle = "#ffffff";
ctx.shadowColor = "#38bdf8";
ctx.shadowBlur = 24;
ctx.beginPath();
ctx.arc(cx, cy, 6 * scale, 0, Math.PI * 2);
ctx.fill();
ctx.shadowBlur = 0;
for (let i = 0; i < STARS; i++) {
starTheta[i] += starSpeed[i] / (starR[i] * 0.4 + 10) * 0.4;
const armPhase = 1 / pitch * Math.log(starR[i] / 10) - t * 0.4;
const distToArm = Math.sin(arms * (starTheta[i] - armPhase));
const effectiveR = starR[i] * (1 - 0.12 * distToArm);
const px = cx + Math.cos(starTheta[i]) * effectiveR * scale;
const py = cy + Math.sin(starTheta[i]) * effectiveR * scale;
const isArm = distToArm > 0.3;
const hue = isArm ? (200 + starR[i] * 0.3) % 360 : (270 + starR[i] * 0.4) % 360;
const alpha = Math.min(1, Math.max(0.15, (1 - starR[i] / 240) * (isArm ? 1 : 0.4)));
ctx.fillStyle = hsla(hue, 90, 70, alpha);
ctx.fillRect(px, py, 1.5 * scale, 1.5 * scale);
}
}
};
}
// Default parameters from content metadata
const defaultParams = [
{
"key": "armCount",
"label": "Spiral Arm Count (m)",
"type": "range",
"min": 1,
"max": 6,
"step": 1,
"defaultValue": 2,
"description": "Number of density wave spiral arms"
},
{
"key": "pitchAngle",
"label": "Arm Pitch Angle",
"type": "range",
"min": 0.1,
"max": 0.5,
"step": 0.02,
"defaultValue": 0.22,
"description": "Logarithmic winding tightness"
},
{
"key": "speed",
"label": "Pattern Speed (Ωp)",
"type": "range",
"min": 0.2,
"max": 2,
"step": 0.1,
"defaultValue": 0.6,
"description": "Rigid wave pattern rotation"
}
];
if (!window.__art_instances) window.__art_instances = {};
if (!window.__art_instances['galaxy-spiral-density']) {
const inst = typeof createGalaxySpiralDensity === 'function' ? createGalaxySpiralDensity() : null;
if (inst && inst.setup) {
inst.setup({ ctx, width, height, dpr: 1, aspectRatio: width / height }, defaultParams);
}
window.__art_instances['galaxy-spiral-density'] = inst;
}
const instance = window.__art_instances['galaxy-spiral-density'];
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
Σ(r,θ,t)=Σ0(r)+Σ1(r)cos[m(θ−Ωpt−f(r))],f(r)=taniln(r/r0)
Click to expand
∑
Spiral Galaxy Density
Full Mathematical System • space
100%
Complete System of Equations
[Governing Law][Discrete Progression]theta−armPhase)))[Domain & Space][Parameter State]Σ(r,θ,t)=Σ0(r)+Σ1(r)cos[m(θ−Ωpt−f(r))],f(r)=taniln(r/r0)armPhase=(1/pitch)⋅ln(r/10)−0.4t,reff=r⋅(1−0.12⋅sin(m⋅(x∈R2,t∈R+,ω∈[0,2π]λarmCount=2(Spiral Arm Count (m)),λpitchAngle=0.22(Arm Pitch Angle),λspeed=0.6(Pattern Speed (Ωp))
Σ(r,θ,t)=Σ0(r)+Σ1(r)cos[m(θ−Ωpt−f(r))],f(r)=taniln(r/r0)
Computational Implementation (JavaScript Engine Equivalent)
armPhase = (1/pitch) * ln(r/10) - 0.4t, r_eff = r * (1 - 0.12 * sin(m*(θ - armPhase))) Compact Formula
armPhase = (1/pitch) * ln(r/10) - 0.4t, r_eff = r * (1 - 0.12 * sin(m*(θ - armPhase))) Mathematical Tags
#galaxy
#density-wave
#astrophysics
#spiral
#space
#stars
Author: Math Art Core Target: 60 FPS
Press ESC or F to exit