Tests für rot_2D und rot_3D

This commit is contained in:
Lena committed 2026-10-28 21:29:44 +01:00
1 parent 70e1a351f3
commit 7753115638
6 files changed
+196 -54

No files matched your search

+15 -14
View File
@@ -1,4 +1,3 @@
import pygame
from compute import matmul, rot_2D
@@ -11,7 +10,6 @@ WHITE = (255, 255, 255)
BLUE = (0, 0, 255)
class Moon(Game):
"""Der Mond kreist um die Erde."""
@@ -20,7 +18,7 @@ class Moon(Game):
title: str = "Moon",
fps: int = 60,
size: tuple[int, int] = (640, 400),
) -> None:
) -> None:
"""Legt Startposition, Drehwinkel und Rotationsmatrix fest."""
super().__init__(title, fps, size)
self.position_moon: tuple[float, float] = (
@@ -30,8 +28,6 @@ class Moon(Game):
self.theta = 0.05
self.rot_moon = rot_2D(self.theta)
def update_game(self) -> bool:
"""Dreht den Mond ein Stück weiter."""
self.move_moon()
@@ -46,23 +42,28 @@ class Moon(Game):
point = [[dx], [dy]]
result = matmul(self.rot_moon, point)
# new absolute position
self.position_moon = (earth_center[0] + result[0][0], earth_center[1] + result[1][0])
self.position_moon = (
earth_center[0] + result[0][0],
earth_center[1] + result[1][0],
)
def draw_game(self) -> None:
"""Zeichnet Erde und Mond."""
self.screen.fill(BLACK)
earth_pos = (self.size[0] // 2, self.size[1] // 2)
pygame.draw.circle(self.screen, BLUE, earth_pos, EARTH_RADIUS)
pygame.draw.circle(self.screen, WHITE, (int(self.position_moon[0]), int(self.position_moon[1])), MOON_RADIUS)
pygame.draw.circle(
self.screen,
WHITE,
(int(self.position_moon[0]), int(self.position_moon[1])),
MOON_RADIUS,
)
if __name__ == "__main__":
moon = Moon()
moon.run()
moon = Moon()
moon.run()
#source .venv/bin/activate
#python moon.py
# source .venv/bin/activate
# python moon.py