Project 8: Spiral Art Generator 🌀¶
Difficulty: 🟢 Beginner
Run cells top to bottom. Each step builds on the previous one and saves real files under outputs/spiral_art_generator/.
Description¶
Draw mesmerizing golden-ratio spirals and colorful archimedean spirals using matplotlib — math becomes art.
Libraries & Modules¶
numpy—linspace, trigonometrymatplotlib.pyplot
Python Concepts You'll Practice¶
NumPy arrays, polar-like parametric curves, plotting
🎛️ Parameter Variations¶
SPIRAL_TYPE—'golden'or'archimedean'TURNS— 3 vs 12 rotationsCOLOR/LINEWIDTH— visual styleDPI— export resolution
In [1]:
# Install dependencies for this project (safe to re-run)
import sys
!{sys.executable} -m pip install pillow numpy matplotlib wordcloud qrcode[pil] python-barcode fpdf2 jinja2 folium plotly pandas scipy ipywidgets -q
Skipping pip install (already installed)
In [2]:
# Interactive Jupyter setup — run this cell first
%matplotlib inline
from pathlib import Path
from IPython.display import display, Image as IPImage, HTML, Markdown, Audio, IFrame
OUTPUT_DIR = Path("outputs") / "spiral_art_generator"
OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
print(f"✅ Outputs folder: {OUTPUT_DIR.resolve()}")
✅ Outputs folder: C:\Users\Hansel Yan\Projects\CodeItAll\outputs\spiral_art_generator
Step 1 — Generate spiral coordinates¶
In [3]:
import numpy as np
import matplotlib.pyplot as plt
# 🎛️ TWEAK THESE
SPIRAL_TYPE = "golden" # "golden" | "archimedean"
TURNS = 8
POINTS = 2000
COLOR = "#e94560"
LINEWIDTH = 1.5
DPI = 150
PHI = (1 + 5**0.5) / 2
theta = np.linspace(0, TURNS * 2 * np.pi, POINTS)
if SPIRAL_TYPE == "golden":
r = np.exp(theta / (2 * np.pi) * np.log(PHI))
else:
r = theta
x = r * np.cos(theta)
y = r * np.sin(theta)
print(f"{SPIRAL_TYPE} spiral: {TURNS} turns, {POINTS} points")
golden spiral: 8 turns, 2000 points
Step 2 — Plot and save¶
In [4]:
fig, ax = plt.subplots(figsize=(8, 8), facecolor="#0f0f23")
ax.set_facecolor("#0f0f23")
ax.plot(x, y, color=COLOR, linewidth=LINEWIDTH)
ax.set_aspect("equal")
ax.axis("off")
ax.set_title("Spiral Art Generator — CodeItAll", color="white", fontsize=14, pad=12)
out = OUTPUT_DIR / f"spiral_{SPIRAL_TYPE}.png"
fig.savefig(out, dpi=DPI, bbox_inches="tight", facecolor=fig.get_facecolor())
plt.show()
print(f"Saved to {out}")
Saved to outputs\spiral_art_generator\spiral_golden.png
✅ Project complete¶
Check your output folder: outputs/spiral_art_generator/
Next: Project 9: Barcode Factory · Index