Galaxy Spiral Arms¶
By the end of this lab you'll be able to:
- Model galaxy spiral arms using logarithmic spirals offset by 180°
- Scatter star dots along spiral arms with random offsets
- Use different dot sizes and colors to simulate star brightness
A two-armed spiral galaxy with scattered star dots forming the arms, a dense central bulge, and background stars. The arms follow logarithmic spirals, just like the Milky Way.
Welcome to the Galaxy!
Galaxies like the Milky Way have spiral arms that follow logarithmic curves.
In this lab you'll build a mini galaxy using that same math!
Let's code it together!
How It Works¶
For each arm, place dots at positions r = scale * exp(b * theta) for theta from 0 to 3π. The second arm is offset by π (180°). Each star dot gets a random scatter from its ideal position. The center bulge is a dense cluster of dots at small radii.
Sample Code¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | |
What Do You Think Will Happen?
Each arm has 300 dots scattered around a logarithmic spiral.
Will the arms look like tight curves or spread-out clouds of stars?
Make your guess — then click Run to find out!
Try It Now¶
Spread-out clouds — the Gaussian scatter makes the arms look like fuzzy bands rather than thin lines, just like real galaxy photos. Were you right?
How It Works¶
random.gauss(0, 4) adds Gaussian (bell-curve) random scatter. Most stars are near the ideal spiral, but a few stray far. The central bulge uses random.gauss(0, 20) — a tighter cluster.
Explanation Table¶
| Line | What it does |
|---|---|
b = 0.25 |
Spiral tightness parameter |
math.exp(b * theta) |
Logarithmic spiral — grows exponentially |
offset = arm * math.pi |
Rotate second arm by 180° |
random.gauss(0, 4) |
Gaussian scatter around the spiral path |
Learning Check¶
Your Turn — Add a Third Arm
Change range(2) to range(3) and offset = arm * math.pi to offset = arm * 2 * math.pi / 3.
A three-armed galaxy! What angle offset does each arm need?
Three arms at 120° spacing — like the Triangulum Galaxy, which actually has this structure!
Experiments¶
-
Change the scatter. Change
random.gauss(0, 4)torandom.gauss(0, 10). You'll know it worked when the arms look fuzzier and more diffuse. -
Tighter spiral. Change
b = 0.25tob = 0.4. You'll know it worked when the arms wind more steeply inward. -
Larger galaxy. Change
12to8andrange(300)torange(500). You'll know it worked when the arms extend further and have more stars. -
Color by distance. Make inner stars yellow and outer stars blue — hotter stars near the center, cooler at the edge. You'll know it worked when the color gradient follows the arms.
You Built a Galaxy!
You modeled spiral galaxy arms with logarithmic spirals and Gaussian scatter!
Real astrophysicists use the same mathematical models to map the Milky Way.
Up next: Ripple Waves — concentric rings that simulate water ripples.