Initial commit
This commit is contained in:
commit
44ddaddc7f
8
.idea/.gitignore
generated
vendored
Normal file
8
.idea/.gitignore
generated
vendored
Normal file
@ -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
|
||||||
10
.idea/Semester_3.iml
generated
Normal file
10
.idea/Semester_3.iml
generated
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="PYTHON_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/.venv" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="jdk" jdkName="Python 3.12" jdkType="Python SDK" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
6
.idea/inspectionProfiles/profiles_settings.xml
generated
Normal file
6
.idea/inspectionProfiles/profiles_settings.xml
generated
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<settings>
|
||||||
|
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||||
|
<version value="1.0" />
|
||||||
|
</settings>
|
||||||
|
</component>
|
||||||
7
.idea/misc.xml
generated
Normal file
7
.idea/misc.xml
generated
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Black">
|
||||||
|
<option name="sdkName" value="Python 3.12 (Semester_3)" />
|
||||||
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.12" project-jdk-type="Python SDK" />
|
||||||
|
</project>
|
||||||
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/Semester_3.iml" filepath="$PROJECT_DIR$/.idea/Semester_3.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
BIN
lab_01/__pycache__/compute.cpython-312.pyc
Normal file
BIN
lab_01/__pycache__/compute.cpython-312.pyc
Normal file
Binary file not shown.
BIN
lab_01/__pycache__/game.cpython-312.pyc
Normal file
BIN
lab_01/__pycache__/game.cpython-312.pyc
Normal file
Binary file not shown.
BIN
lab_01/__pycache__/moon.cpython-312.pyc
Normal file
BIN
lab_01/__pycache__/moon.cpython-312.pyc
Normal file
Binary file not shown.
53
lab_01/apollo.py
Normal file
53
lab_01/apollo.py
Normal file
@ -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()
|
||||||
|
|
||||||
144
lab_01/compute.py
Normal file
144
lab_01/compute.py
Normal file
@ -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)
|
||||||
37
lab_01/first_task.py
Normal file
37
lab_01/first_task.py
Normal file
@ -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]))
|
||||||
53
lab_01/game.py
Normal file
53
lab_01/game.py
Normal file
@ -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()
|
||||||
|
|
||||||
42
lab_01/moon.py
Normal file
42
lab_01/moon.py
Normal file
@ -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()
|
||||||
|
|
||||||
12
requirements.txt
Normal file
12
requirements.txt
Normal file
@ -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
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user