From 24fd61a35d9c8f9006ed9c18d963307dc62674d6 Mon Sep 17 00:00:00 2001 From: Selin Date: Thu, 15 Oct 2026 17:06:47 +0200 Subject: [PATCH] Initial commit --- .gitignore | 2 + Praktikumsaufgaben/Moon.py | 78 +++++++++++++++++++++++ Praktikumsaufgaben/compute.py | 114 ++++++++++++++++++++++++++++++++++ Praktikumsaufgaben/game.py | 52 ++++++++++++++++ opencode.json | 16 +++++ 5 files changed, 262 insertions(+) create mode 100644 .gitignore create mode 100644 Praktikumsaufgaben/Moon.py create mode 100644 Praktikumsaufgaben/compute.py create mode 100644 Praktikumsaufgaben/game.py create mode 100644 opencode.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7a60b85 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +__pycache__/ +*.pyc diff --git a/Praktikumsaufgaben/Moon.py b/Praktikumsaufgaben/Moon.py new file mode 100644 index 0000000..90cdee3 --- /dev/null +++ b/Praktikumsaufgaben/Moon.py @@ -0,0 +1,78 @@ +import pygame +from Praktikumsaufgaben.compute import matmul, rot_2D, transpose, rotate +from game import Game + +EARTH_RADIUS = 30 +MOON_RADIUS = 10 + +BLACK = (0, 0, 0) +WHITE = (255, 255, 255) +BLUE = (0, 0, 255) + + +class Moon(Game): + """Der Mond kreist um die Erde.""" + + def __init__( + self, + title: str = "Moon", + fps: int = 60, + size: tuple[int, int] = (640, 400), + ) -> None: + """Legt Startposition, Drehwinkel und Rotationsmatrix fest.""" + super().__init__(title, fps, size) + + # TODO: Startposition des Mondes festlegen + self.position_moon = (100, 0) + + # TODO: Drehwinkel pro Bild festlegen + self.theta = 0.001 # je grösser theta desto schneller dreht sich der mond + + # TODO: Rotationsmatrix berechnen + self.rot_moon = rot_2D(self.theta) + + def update_game(self) -> bool: + """Dreht den Mond ein Stück weiter.""" + + # TODO: Mondposition mit der Rotationsmatrix weiterdrehen + point = transpose([list(self.position_moon)]) #koordinaten zur liste, transpose wandelt diese in zeilenmatrix um + result = matmul(self.rot_moon, point) #multiplizieet die mondposition mit der rotationsmatrix + self.position_moon = (result[0][0], result[1][0]) #speichert einf die nuee pos + return True + + def draw_game(self) -> None: + """Zeichnet Erde und Mond.""" + + # TODO: Bildschirm löschen + self.screen.fill(BLACK) + + center_x = self.size[0] // 2 + center_y = self.size[1] // 2 #hiermit berchnen wir den mittelpunkt des fensters + + # TODO: Erde zeichnen + pygame.draw.circle( + self.screen, + BLUE, + (center_x, center_y), + EARTH_RADIUS + ) + + # TODO: Mond zeichnen + moon_x = center_x + self.position_moon[0] #zuerst die pos berechnen + moon_y = center_y + self.position_moon[1] #abstand zur erde + + pygame.draw.circle( + self.screen, + WHITE, + (int(moon_x), int(moon_y)), + MOON_RADIUS + ) + + # TODO: Bild anzeigen + pygame.display.flip() + + +if __name__ == "__main__": + # TODO: Moon-Objekt erzeugen und starten + moon = Moon() + moon.run() \ No newline at end of file diff --git a/Praktikumsaufgaben/compute.py b/Praktikumsaufgaben/compute.py new file mode 100644 index 0000000..fa9925c --- /dev/null +++ b/Praktikumsaufgaben/compute.py @@ -0,0 +1,114 @@ +# Prog3B/compute.py + +"""Matrix transpose implementation. + +The function `transpose` accepts a 2‑D list `matrix` and returns a new +2‑D list where rows and columns are swapped. The implementation uses +simple for‑loops and basic list operations to stay within the beginner +Python skill level. + +Example +------- +>>> transpose([[1, 2, 3], [4, 5, 6]]) +[[1, 4], [2, 5], [3, 6]] + +""" + +from typing import List, Any +import math + + +def transpose(matrix: List[List[Any]]) -> List[List[Any]]: + """Return the transpose of a rectangular matrix. + + Parameters + ---------- + matrix: list of list + A non‑empty 2‑D list where each sub‑list represents a row. All + rows are assumed to be the same length. + + Returns + ------- + list of list + A new matrix where the i‑th row of the result contains the i‑th + column of the input. + """ + if not matrix: + return [] + + rows = len(matrix) + cols = len(matrix[0]) + + # initialise result with correct dimensions + result: List[List[Any]] = [[0] * rows for _ in range(cols)] + + for i in range(rows): + for j in range(cols): + result[j][i] = matrix[i][j] + + return result + + +def rotate(matrix: List[List[Any]]) -> List[List[Any]]: + """Return a new matrix rotated 90 degrees clockwise. + + The original matrix is not modified. + + Parameters + ---------- + matrix: list of list + A rectangular matrix. + + Returns + ------- + list of list + Rotated matrix. + """ + if not matrix: + return [] + inter = transpose(matrix) + rows = len(inter); cols = len(inter[0]) + result: List[List[Any]] = [[0] * rows for _ in range(cols)] + for i in range(cols): + for j in range(rows): + result[i][j] = inter[rows - 1 - j][i] + return result + +def rot_2D(theta): + """Erzeugt eine Rotationsmatrix für einen Winkel.""" + + return [ + [math.cos(theta), -math.sin(theta)], + [math.sin(theta), math.cos(theta)] + ] + +def matmul(A, B): + """Multipliziert zwei Matrizen.""" + + rows_A = len(A) + cols_A = len(A[0]) + cols_B = len(B[0]) + + if cols_A != len(B): + raise ValueError("Matrizen können nicht multipliziert werden") + + result = [[0] * cols_B for _ in range(rows_A)] + + for i in range(rows_A): + for j in range(cols_B): + for k in range(cols_A): + result[i][j] += A[i][k] * B[k][j] + + return result + + +if __name__ == "__main__": + # simple demonstration / sanity check + sample = [[1, 2, 3], [4, 5, 6]] + print("Input:") + print(sample) + print("\nTransposed:") + print(transpose(sample)) + print("\nRotated:") + print(rotate(sample)) + diff --git a/Praktikumsaufgaben/game.py b/Praktikumsaufgaben/game.py new file mode 100644 index 0000000..cb2f729 --- /dev/null +++ b/Praktikumsaufgaben/game.py @@ -0,0 +1,52 @@ +import pygame + + +class Game: + """Basisklasse für Pygame-Spiele.""" + + def __init__( + self, + title: str = "Game", + fps: int = 60, + size: tuple[int, int] = (640, 400), + ) -> None: + + pygame.init() + + self.title = title + self.fps = fps + self.size = size + + self.screen = pygame.display.set_mode(size) + pygame.display.set_caption(title) + + self.clock = pygame.time.Clock() + + def update_game(self) -> bool: + """Aktualisiert den Spielzustand.""" + return True + + def draw_game(self) -> None: + """Zeichnet das Spiel.""" + pass + + def run(self) -> None: + """Startet die Spielschleife.""" + + running = True + + while running: + + for event in pygame.event.get(): + if event.type == pygame.QUIT: + running = False + + if running: + running = self.update_game() + + if running: + self.draw_game() + + self.clock.tick(self.fps) + + pygame.quit() \ No newline at end of file diff --git a/opencode.json b/opencode.json new file mode 100644 index 0000000..fdcfe05 --- /dev/null +++ b/opencode.json @@ -0,0 +1,16 @@ +{ + "$schema": "https://opencode.ai/config.json", + "provider": { + "thn": { + "npm": "@ai-sdk/openai-compatible", + "options": { + "baseURL": "http://141.75.33.244:8000/v1", + "apiKey": "sk-QXj1p40XOwNSze_5-eYrBzVh3qIgAfqoWPkAjNVqOS8" + }, + "models": { + "gpt-oss:20b": { "name": "GPT-OSS 20B" } + } + } + }, + "model": "thn/gpt-oss:20b" +}