feat: Add geometry module demo system for orbital mechanics
Creates comprehensive visual demonstrations of the geometry module: Static demos: - Bresenham algorithms: circle/line rasterization on grid cells - Angle calculations: line elements showing angles between points, waypoint viability with angle thresholds, orbit exit headings - Pathfinding: planets with surfaces and orbit rings, optimal path using orbital slingshots vs direct path comparison Animated demos: - Solar system: planets orbiting star with discrete time steps, nested moon orbit, position updates every second - Pathfinding through moving system: ship navigates to target using orbital intercepts, anticipating planetary motion Includes 5 screenshot outputs demonstrating each feature. Run: ./mcrogueface --headless --exec tests/geometry_demo/geometry_main.py Interactive: ./mcrogueface tests/geometry_demo/geometry_main.py 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
bc95cb1f0b
commit
198686cba9
14 changed files with 1718 additions and 0 deletions
84
tests/geometry_demo/screens/base.py
Normal file
84
tests/geometry_demo/screens/base.py
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
"""Base class for geometry demo screens."""
|
||||
import mcrfpy
|
||||
import sys
|
||||
import os
|
||||
|
||||
# Add scripts path for geometry module
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..', '..', 'src', 'scripts'))
|
||||
from geometry import *
|
||||
|
||||
|
||||
class GeometryDemoScreen:
|
||||
"""Base class for geometry demo screens."""
|
||||
|
||||
name = "Base Screen"
|
||||
description = "Override this description"
|
||||
|
||||
def __init__(self, scene_name):
|
||||
self.scene_name = scene_name
|
||||
mcrfpy.createScene(scene_name)
|
||||
self.ui = mcrfpy.sceneUI(scene_name)
|
||||
self.timers = [] # Track timer names for cleanup
|
||||
|
||||
def setup(self):
|
||||
"""Override to set up the screen content."""
|
||||
pass
|
||||
|
||||
def cleanup(self):
|
||||
"""Clean up timers when leaving screen."""
|
||||
for timer_name in self.timers:
|
||||
try:
|
||||
mcrfpy.delTimer(timer_name)
|
||||
except:
|
||||
pass
|
||||
|
||||
def get_screenshot_name(self):
|
||||
"""Return the screenshot filename for this screen."""
|
||||
return f"{self.scene_name}.png"
|
||||
|
||||
def add_title(self, text, y=10):
|
||||
"""Add a title caption."""
|
||||
title = mcrfpy.Caption(text=text, pos=(400, y))
|
||||
title.fill_color = mcrfpy.Color(255, 255, 255)
|
||||
title.outline = 2
|
||||
title.outline_color = mcrfpy.Color(0, 0, 0)
|
||||
self.ui.append(title)
|
||||
return title
|
||||
|
||||
def add_description(self, text, y=50):
|
||||
"""Add a description caption."""
|
||||
desc = mcrfpy.Caption(text=text, pos=(50, y))
|
||||
desc.fill_color = mcrfpy.Color(200, 200, 200)
|
||||
self.ui.append(desc)
|
||||
return desc
|
||||
|
||||
def add_label(self, text, x, y, color=(200, 200, 200)):
|
||||
"""Add a label caption."""
|
||||
label = mcrfpy.Caption(text=text, pos=(x, y))
|
||||
label.fill_color = mcrfpy.Color(*color)
|
||||
self.ui.append(label)
|
||||
return label
|
||||
|
||||
def create_grid(self, grid_size, pos, size, cell_size=16):
|
||||
"""Create a grid for visualization."""
|
||||
grid = mcrfpy.Grid(
|
||||
grid_size=grid_size,
|
||||
pos=pos,
|
||||
size=size
|
||||
)
|
||||
grid.fill_color = mcrfpy.Color(20, 20, 30)
|
||||
self.ui.append(grid)
|
||||
return grid
|
||||
|
||||
def color_grid_cell(self, grid, x, y, color):
|
||||
"""Color a specific grid cell."""
|
||||
try:
|
||||
point = grid.at(x, y)
|
||||
point.color = mcrfpy.Color(*color) if isinstance(color, tuple) else color
|
||||
except:
|
||||
pass # Out of bounds
|
||||
|
||||
def add_timer(self, name, callback, interval):
|
||||
"""Add a timer and track it for cleanup."""
|
||||
mcrfpy.setTimer(name, callback, interval)
|
||||
self.timers.append(name)
|
||||
Loading…
Add table
Add a link
Reference in a new issue