From 62a624a1b1ab39301c21694d5e35f9dd23526211 Mon Sep 17 00:00:00 2001 From: Lily Iliana Luna Ylva Anderson Appleseed Grigaitis Date: Fri, 15 Aug 2025 22:27:42 -0500 Subject: [PATCH] init --- main.py | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ shell.nix | 31 ++++++++++++++++++++ 2 files changed, 115 insertions(+) create mode 100644 main.py create mode 100644 shell.nix diff --git a/main.py b/main.py new file mode 100644 index 0000000..efbe1ce --- /dev/null +++ b/main.py @@ -0,0 +1,84 @@ +import pygame +from kingdon import Algebra +import math + +ERROR = 0.00001 + +alg = Algebra(2,1,0) +locals().update(alg.blades) +b = 2*e12 +print(b) + +def motor(generator): + bivector = generator.grade(2) + sqr = (bivector*bivector).grade(0).e + mag = bivector.norm().e + generator = bivector.normalized() + if mag < ERROR: + #Zero Norm + return 1+bivector + elif sqr < 0: + return math.cos(mag) + math.sin(mag)*generator + else: + return math.cosh(mag) + math.sinh(mag)*generator + +motor(1*e12) +motor(1*e13) +motor(1*e23) + + + + + + + +''' +# Initialize Pygame +pygame.init() + +# Set up the screen +WIDTH, HEIGHT = 800, 600 +screen = pygame.display.set_mode((WIDTH, HEIGHT)) +pygame.display.set_caption("Clifford and Pygame Example") + +# Colors +BLACK = (0, 0, 0) +WHITE = (255, 255, 255) +RED = (255, 0, 0) + +# Initial point in GA (e.g., a vector representing a point) +# We'll represent it as a multivector with a vector component +initial_point_ga = 100 * e1 + 50 * e2 + +# Create a rotor for rotation (e.g., 45 degrees counter-clockwise) +angle = math.pi / 4 # 45 degrees +rotor = math.e**(angle * e12) + +# Game loop +running = True +while running: + for event in pygame.event.get(): + if event.type == pygame.QUIT: + running = False + + # Clear the screen + screen.fill(BLACK) + + # Apply the rotation to the point + rotated_point_ga = rotor * initial_point_ga * ~rotor + + # Extract the vector components for Pygame display + # We assume the point is a vector, so we access its e1 and e2 components + x_coord = rotated_point_ga.value[e1.index] + WIDTH // 2 # Adjust for screen center + y_coord = -rotated_point_ga.value[e2.index] + HEIGHT // 2 # Invert y for Pygame coordinates + + # Draw the point + pygame.draw.circle(screen, RED, (int(x_coord), int(y_coord)), 5) + + # Update the display + pygame.display.flip() + +# Quit Pygame +pygame.quit() +''' + diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..0a7a8aa --- /dev/null +++ b/shell.nix @@ -0,0 +1,31 @@ +{ pkgs ? import {} }: + +pkgs.mkShell { + name = "ga-dev-shell"; + + buildInputs = with pkgs; [ + python3 + python3Packages.pip + python3Packages.numpy + python3Packages.matplotlib + python3Packages.pygame + + # Optional: use pip to install clifford in virtualenv + ]; + + shellHook = '' + echo "Python environment with pygame and numpy ready." + + # Optional: set up venv and install clifford via pip if needed + if [ ! -d .venv ]; then + python -m venv .venv + source .venv/bin/activate + pip install --upgrade pip + pip install kingdon + echo "Installed clifford in virtual environment." + else + source .venv/bin/activate + echo "Activated existing virtual environment." + fi + ''; +}