Skip to content

mich1803/Two-Suns-Gravity-Visualizer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

Project contents

  • 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.

Web interface

You can run locally by opening index.html directly, or on https://mich1803.github.io/Two-Suns-Gravity-Visualizer/ .

Features

  • 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.

How the simulation works

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))*dt
  • r(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.


Python CLI usage

Dependencies

pip install numpy pillow tqdm

Example

python 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-6

12 August 2025 <3

About

A simple python codebase for simulating a Two-Suns System. Can generate cool visualizations.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors