-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
111 lines (93 loc) · 4.28 KB
/
main.py
File metadata and controls
111 lines (93 loc) · 4.28 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
"""
TurtleAnimations — Main Launcher
=================================
Run this file from the repo root:
python main.py
Works for ALL animations, including those that import from core/,
physics/, projections/, etc. — because we add the project root to
sys.path before loading any script.
"""
import os
import sys
import importlib.util
# ── Make sure every sub-module can find 'core', 'physics', etc. ──────────────
ROOT = os.path.dirname(os.path.abspath(__file__))
if ROOT not in sys.path:
sys.path.insert(0, ROOT)
# ── Full animation menu ───────────────────────────────────────────────────────
MENU = {
# Legacy
"1": ("💖 Parametric Heart", "legacy/parametric_heart.py"),
"2": ("🌀 Arc Weave", "legacy/arc_weave.py"),
"3": ("🌈 Rainbow Geometric Wheel", "legacy/geometricRainbow_wheel.py"),
"4": ("☀️ Sunburst Spiral", "legacy/sunburst_spiral.py"),
# Fractals
"5": ("🌑 Mandelbrot Visualizer", "fractals/mandelbrot_visualizer.py"),
"6": ("🔵 Julia Set Explorer", "fractals/julia_set_explorer.py"),
# Interactive
"7": ("🎆 Keyboard Fireworks", "interactive/keyboard_fireworks.py"),
"8": ("〰️ Lissajous Controller", "interactive/lissajous_controller.py"),
"9": ("🖌️ Mouse Painter", "interactive/mouse_painter.py"),
# Physics
"10": ("🌌 Galaxy Simulation", "physics/galaxy.py"),
"11": ("🌟 Neon Particles", "physics/neon.py"),
"12": ("🔵 Particle Presets", "physics/presets.py"),
}
BANNER = r"""
╔════════════════════════════════════════════════════╗
║ 🐢 T U R T L E A N I M A T I O N S 🐢 ║
║ Where Mathematics Becomes Art ║
╠════════════════════════════════════════════════════╣
║ github.com/Aaricacoding/TurtleAnimations ║
╚════════════════════════════════════════════════════╝
"""
CATEGORIES = [
("📦 LEGACY", ["1", "2", "3", "4"]),
("🌿 FRACTALS", ["5", "6"]),
("🎮 INTERACTIVE", ["7", "8", "9"]),
("🌊 PHYSICS", ["10", "11", "12"]),
]
def run_script(path: str) -> None:
"""Dynamically load and run an animation script with ROOT on sys.path."""
abs_path = os.path.join(ROOT, path)
if not os.path.exists(abs_path):
print(f"\n ⚠ File not found: {abs_path}\n")
return
spec = importlib.util.spec_from_file_location("animation", abs_path)
mod = importlib.util.module_from_spec(spec)
# Give the loaded module the same root path awareness
sys.modules["animation"] = mod
spec.loader.exec_module(mod)
# New-style animations expose a run() entry point; legacy scripts run at
# module level, so we only call run() when it actually exists.
if hasattr(mod, "run") and callable(mod.run):
mod.run()
def print_menu() -> None:
print(BANNER)
for category, keys in CATEGORIES:
print(f" {category}")
for k in keys:
label, _ = MENU[k]
print(f" [{k:>2}] {label}")
print()
print(" [ q] Quit\n")
def main() -> None:
while True:
print_menu()
choice = input(" Enter a number to launch: ").strip().lower()
if choice == "q":
print("\n See you next time! ✦\n")
break
if choice not in MENU:
print("\n ⚠ Invalid choice — try again.\n")
input(" Press Enter to continue...")
print("\033[2J\033[H") # clear terminal
continue
label, path = MENU[choice]
print(f"\n ► Launching {label} ...\n")
run_script(path)
print("\n Animation closed.")
input(" Press Enter to return to menu...")
print("\033[2J\033[H") # clear terminal
if __name__ == "__main__":
main()