Two fixed “suns” pull a mass from every pixel; each pixel is colored by the sun that ultimately captures it. The result is a basin-of-attraction visualization.
index.html: GitHub-hostable browser interface (no backend needed). It lets you set image dimensions, choose both sun colors, click to place both suns, render, preview, and download PNG.two_suns.py: Python CLI renderer for generating the same style of image from terminal parameters.preview.ipynb: Notebook playground.
You can run locally by opening index.html directly, or on https://mich1803.github.io/Two-Suns-Gravity-Visualizer/ .
- Select image width/height.
- Select colors for sun 1 and sun 2.
- Click on the white canvas to place each sun (2 clicks).
- Process/render the final visualization.
- Download the generated result as a PNG.
Each pixel coordinate starts as a test particle position r(0) = (x, y) with zero velocity. Two suns are fixed at r1 and r2.
Acceleration:
a(r) = G * ((r1 - r)/|r1-r|^3 + (r2 - r)/|r2-r|^3)
To avoid singularities near sun centers, distances are softened with a small eps term.
Integration uses semi-implicit Euler:
v(t+dt) = v(t) + a(r(t))*dtr(t+dt) = r(t) + v(t+dt)*dt
Capture rule:
A pixel is captured by sun i once it enters capture_radius from that sun. If no capture occurs by max_steps, it is assigned to the nearer sun at the final step.
pip install numpy pillow tqdmpython two_suns.py \
--size 500 500 \
--sun1 160 185 \
--sun2 340 185 \
--color1 "#ff7f0e" \
--color2 "#87ceeb" \
--out basins.png \
--G 10000 --dt 0.25 \
--capture_radius 3.5 \
--max_steps 2400 \
--eps 1e-612 August 2025 <3
