From 44ddaddc7f97540d0544690317e9e260720a1e8a Mon Sep 17 00:00:00 2001 From: Julia Date: Thu, 30 Oct 2025 16:47:01 +0100 Subject: [PATCH] Initial commit --- .idea/.gitignore | 8 + .idea/Semester_3.iml | 10 ++ .../inspectionProfiles/profiles_settings.xml | 6 + .idea/misc.xml | 7 + .idea/modules.xml | 8 + .idea/vcs.xml | 6 + lab_01/__pycache__/compute.cpython-312.pyc | Bin 0 -> 4437 bytes lab_01/__pycache__/game.cpython-312.pyc | Bin 0 -> 2879 bytes lab_01/__pycache__/moon.cpython-312.pyc | Bin 0 -> 2717 bytes lab_01/apollo.py | 53 +++++++ lab_01/compute.py | 144 ++++++++++++++++++ lab_01/first_task.py | 37 +++++ lab_01/game.py | 53 +++++++ lab_01/moon.py | 42 +++++ requirements.txt | 12 ++ 15 files changed, 386 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/Semester_3.iml create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 lab_01/__pycache__/compute.cpython-312.pyc create mode 100644 lab_01/__pycache__/game.cpython-312.pyc create mode 100644 lab_01/__pycache__/moon.cpython-312.pyc create mode 100644 lab_01/apollo.py create mode 100644 lab_01/compute.py create mode 100644 lab_01/first_task.py create mode 100644 lab_01/game.py create mode 100644 lab_01/moon.py create mode 100644 requirements.txt diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/Semester_3.iml b/.idea/Semester_3.iml new file mode 100644 index 0000000..6cb8b9a --- /dev/null +++ b/.idea/Semester_3.iml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..a0256de --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..e738994 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/lab_01/__pycache__/compute.cpython-312.pyc b/lab_01/__pycache__/compute.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..eec78331c0e1b502e9f93d097025acb177d772e5 GIT binary patch literal 4437 zcmb7HU2GKB6~6PgJNy6R^*MG z5X?K|hU$1AKv+)A(XLI_tk5bi1##RwjsmH?4$?u+1YJ8 z$}s=uYR+8Ek=42YN1{&#&PDF5y6+TkkugungbbhIF1-x5>C)|{0VH$PwLfPvY=#3J zVVIw?XY6NDn4es5O7O(hv9zv9v1C%h>NqfI8Rn8>skBDr9iuTEOGy>4cF=F)?PzR^ zY^Ww1s>mvS?~sykEs}a+i*+(btP*Q`GFB?R7&WHly(<)(A)t_mSt{`@1^^)sfWTp%vOCOvZ+y`wtAp)zs*iuDm!pVKkUKgU6%b@u=x>90IfCeA;h;WKr3R{DExWiqCH) zpVu`{+gDw_oc-!+3q8v&X~iANGc%`V`pNO{M0(Wp95;?7#1C%D+(PD~^^XNa_d4W~t?ma7&W@amLPX6D#g8xL!yoWO18(Ufb`N{jW#_hE(m*;XU_LFR#z zc`b6`hKUxC{|zAbWxN@bag$$@@lnc{Uk@2gLI_gS@Xj^?YIrj)Q`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;1$ z=pm#AQMLxg*~TiCm5@A#(>4I(aF(H*Z2n5Uq0cGXIGhOXWYc`x`eNJq8}Hm+dso?0 zhEjr69-*@w%HKeEtVC3vF#zJj=q>Udw=QJCmIbw!u;-+jB13f%pZ?2L9Pbt zX`vYP+e7s>aDpF}8m*Xj^b4uXclqZ9J5_Hk+#yzrDt6_ZX=r53M!?Dt%q@?1l8oj^Psg)0D}^wHe6OF z8$Ss{Au^}TX*y+1A1QWr6_<6*s+$V*f9>#A_)BUpD(#coukM`MIW140zS%f!+a3|z=UC0nii$(SqNQpew`q9 z(?4Lmn_rgC$9pB?W(szVxDr+qhDquM6X|4T4B9G&iETpm0y2CDtP7YM>ONd~Pi!M9 z(Q&pDEg~CBU5CGCsNj7<*;RJCdEjfi(X_A|<6IFPD@CU=7Rj zYN>u%K3q~G`A{j?n3o<%?R0lx`vU@>dpn4v7P3ExZ9j$^K6*L7za%N=``+*S;Ej7S Jk=pse{{VI0CU5`% literal 0 HcmV?d00001 diff --git a/lab_01/apollo.py b/lab_01/apollo.py new file mode 100644 index 0000000..bceb414 --- /dev/null +++ b/lab_01/apollo.py @@ -0,0 +1,53 @@ +from game import Game +from moon import Moon +from compute import * +import pygame + +WHITE = (255, 255, 255) +BLACK = (0,0,0) +RED = (255,0,0) +BLUE = (0,0, 255) +EARTH_RADIUS = 100 +MOON_RADIUS = 20 +AP_RADIUS = 5 + + +class Apollo(Moon): + def __init__(self, title="Apollo", fps=60, size=(640, 400), position_moon=(0, -150), theta=0.01): + super().__init__(title, fps, size) + self.position_moon = position_moon + self.position_ap = (0, 50) + self.theta = theta + self.theta_2 = -0.02 + self.rot_moon = rot_2D(self.theta) + self.rot_ap = rot_2D(self.theta_2) + self.rel_position_ap = (0,30) + self.position_ap = (self.position_moon[0] + self.rel_position_ap[0], + self.position_moon[1] + self.rel_position_ap[1]) + + def update_game(self): + super().update_game() + new_rel_ap = matmul(self.rot_ap, transpose([list(self.rel_position_ap)])) + self.rel_position_ap = (new_rel_ap[0][0], new_rel_ap[1][0]) + + self.position_ap = (self.position_moon[0] + self.rel_position_ap[0], + self.position_moon[1] + self.rel_position_ap[1]) + + return True + + def draw_game(self): + super().draw_game() + + def draw_circles(self): + super().draw_circles() + self.draw_circle(self.position_ap, AP_RADIUS, RED) + + def draw_circle(self, position, radius, color): + super().draw_circle(position, radius, color) + + +if __name__ == "__main__": + # created by ChatGPT + game = Apollo() + game.run() + diff --git a/lab_01/compute.py b/lab_01/compute.py new file mode 100644 index 0000000..13d72ba --- /dev/null +++ b/lab_01/compute.py @@ -0,0 +1,144 @@ +from typing import List +import math + +def count_rows_and_columns(matr_a: List[List[int]], matr_b: List[List[int]]) -> List: + """ + counts all rows and columns + :param matr_a: matrix_a + :param matr_b: matrix_b + :return: list of rows and columns of matrix_a and matrix_b + """ + count_ra = 0 + count_rb = 0 + count_ca = 0 + count_cb = 0 + + for element in matr_a : + if type(element) == list: # Prüfen, ob das Element eine Liste ist + count_ra += 1 + + for element in matr_b : + if type(element) == list: # Prüfen, ob das Element eine Liste ist + count_rb += 1 + + count_ca = len(matr_a[0]) + count_cb = len(matr_b[0]) + + if count_ca != count_rb: + raise ValueError("the dimensions of the two matrices dont match") + + list_c_r = [count_ra, count_rb, count_ca, count_cb] + #print( "Matrix A has rows:", count_ra ,"und columns:", count_ca, + # "Matrix B has rows:", count_rb, "and columns:", count_cb) + return list_c_r + +def matmul (matr_a: List[List[int]], matr_b: List[List[int]]) -> List[List[int]]: + """ + multplies two matrices + :param matr_a: Matrix_A + :param matr_b: Matrix_B + :return: product of Matrix_A and Matrix_B + """ + + list_cr = count_rows_and_columns(matr_a, matr_b) + rows_a= list_cr[0] + rows_b = list_cr[1] + columns_a= list_cr[2] + columns_b = list_cr[3] + temp_list = [] + c2 = 0 + c1 = 0 + result = [[0 for _ in range(columns_b)] for _ in range(rows_a)] # durch chat gpt + + + # if columns_a == rows_b: + # print("all good") + for i in range(rows_a): + for j in range(columns_b): + s = 0 + for k in range(columns_a): # durch Chat gpt + s += matr_a[i][k] * matr_b[k][j] + result[i][j] = s + + return result + +def count_solo(matr_a: List[List[int]]) -> List: + """ + counting rows and columns of one matrix only + :param matr_a: matrix a + :return: the number of list and columns + """ + count_ra = 0 + count_ca = 0 + + for element in matr_a : + if type(element) == list: # Prüfen, ob das Element eine Liste ist + count_ra += 1 + count_ca = len(matr_a[0]) + list_c_r = [count_ra, count_ca, ] + return list_c_r + + +def transpose(matr_a: List[List[int]]) -> List[List[int]]: + """ + transposes a matrix + :param matr_a: matrix_a + :return: the transposed matrix + """ + new_list= count_solo(matr_a) + rows = new_list[0] + columns = new_list[1] + + trans_mat = [[0 for _ in range(rows)] for _ in range(columns)] + + for i in range(rows): + for j in range(columns): + trans_mat[j][i] = matr_a[i][j] #kleine ergänzung durch chatti + + return trans_mat + +#def rot_2D(rad: float) -> List[List[int]]: + #if rad <= 0: + # return ValueError + # if rad >= 6.29: #2π=2×3,141592653589793=6,283185307179586 + # return ValueError + # rot_matr = [ + # [math.cos(rad), -math.sin(rad)], + # [math.sin(rad), math.cos(rad)] + # ] + # return rot_matr + +def rot_2D(rad: float) -> List[List[float]]: + rot_matr = [ + [math.cos(rad), -math.sin(rad)], + [math.sin(rad), math.cos(rad)] + ] + return rot_matr + + +if __name__ == "__main__": + matrix_a = [[3, 4, -1, 4], + [-2, 2, 5, 1] + ] + matrix_b = [[1, 3, -2], + [2, 5, 1], + [-1, 4, -4], + [2, 3, 6] + ] + matrix_c = matmul(matrix_a, matrix_b) + print("Ergebnis C = A * B:") + for row in matrix_c: + print(row) + matrix = [ + [1, 2, 3], + [4, 5, 6] + ] + print(transpose(matrix)) + # Erwartete Ausgabe: + # [ + # [1, 4], + # [2, 5], + # [3, 6] + # ] + matr = rot_2D(2) + print(matr) \ No newline at end of file diff --git a/lab_01/first_task.py b/lab_01/first_task.py new file mode 100644 index 0000000..298cf33 --- /dev/null +++ b/lab_01/first_task.py @@ -0,0 +1,37 @@ +from typing import List + +def substring(string: str, start: int, letters: int =None) -> str: + """ + creates a substring from a given string + :param string: the original string + :param start: the start index + :param letters: the amount of letters in the substring + :return: the substring + """ + length = len(string) + if start > length: + raise ValueError ("Start index must be smaller than stringlenght") + if letters is None: + letters = length - start + if letters + start > length: + raise ValueError ("Sum of start and numbers of letters is grater that stringlength") + if start <0: + raise ValueError (" Start must be positive") + return string[start: start+ letters] + +if __name__ == "__main__": + original = "GEEKSFORGEEKS" + print(substring(original, 0, 5)) # Output: GEEKS + print(substring(original, 5)) # Output: FORGEEKS + + +def product (numbers:List)-> int: + temp = 1 + result = 1 + for i in numbers: + result *= i + i += 1 + return result + +if __name__ == "__main__": + print(product([1,2,3])) \ No newline at end of file diff --git a/lab_01/game.py b/lab_01/game.py new file mode 100644 index 0000000..cdb9dff --- /dev/null +++ b/lab_01/game.py @@ -0,0 +1,53 @@ +import pygame + +class Game: + + def __init__(self, title, fps=60, size=(640, 400)): + self.title = title + self.fps = fps + self.size = size + self.clock = pygame.time.Clock() + self.dt = 0 + self.screen = None + + def init_game(self): + pygame.init() + pygame.display.set_caption(self.title) + self.screen = pygame.display.set_mode(self.size) + + + def game_loop(self): + while True: + # Berechnung der Zeitdifferenz seit dem letzten Frame + self.dt = self.clock.tick(self.fps) / 1000 + if self.event_handling() == False: + break + if self.update_game() == False: + break + self.draw_game() + + def exit_game(self): + pygame.quit() + + def event_handling(self): # bleibt in der Unterklasse unverändert + for event in pygame.event.get(): + if not self.handle_event(event): + return False + return True + + def handle_event(self, event): # wird in der Unterklasse überschrieben + if event.type == pygame.QUIT: + return False + return True + + def update_game(self): + return True + + def draw_game(self): + pygame.display.flip() + + def run(self): + self.init_game() + self.game_loop() + self.exit_game() + diff --git a/lab_01/moon.py b/lab_01/moon.py new file mode 100644 index 0000000..69dcfa6 --- /dev/null +++ b/lab_01/moon.py @@ -0,0 +1,42 @@ +from game import Game +from compute import * +import pygame +WHITE = (255, 255, 255) +BLACK = (0,0,0) +EARTH_RADIUS = 100 +MOON_RADIUS = 20 +AP_RADIUS = 5 +BLUE = (0,0, 255) + +class Moon(Game): + def __init__(self, title= "Moon", fps = 60, size= (640,400)): + super().__init__(title, fps, size) + self.position_moon = (0, -500) + self.theta_1 = 0.01 + self.rot_moon = rot_2D(self.theta_1) + + def update_game(self): + new_position = matmul(self.rot_moon, transpose([list(self.position_moon)])) + self.position_moon = (new_position[0][0], new_position[1][0]) + return True + + def draw_game(self): + self.screen.fill(BLACK) + self.draw_circles() + pygame.display.flip() + + def draw_circles(self): + self.draw_circle((0,0), EARTH_RADIUS, BLUE) + self.draw_circle(self.position_moon, MOON_RADIUS, WHITE) + + + + def draw_circle(self, position, radius, color): + x = int(position[0] + self.size[0] //2) + y = int(position[1] + self.size[1] //2) + pygame.draw.circle(self.screen, color,(x,y), radius) + +if __name__ == "__main__": + game = Moon() + game.run() + diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..eba43c3 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,12 @@ +blinker==1.9.0 +click==8.2.0 +colorama==0.4.6 +Flask==3.1.1 +flask-cors==5.0.1 +itsdangerous==2.2.0 +Jinja2==3.1.6 +MarkupSafe==3.0.2 +Werkzeug==3.1.3 +pygame>=2.5,<3.0 +pip +