Initial commit

This commit is contained in:
Selin committed 2026-10-15 17:06:47 +02:00
commit 24fd61a35d
5 files changed
+262

No files matched your search

+2
View File
@@ -0,0 +1,2 @@
__pycache__/
*.pyc
+78
View File
@@ -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()
+114
View File
@@ -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))
+52
View File
@@ -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()
+16
View File
@@ -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"
}