From 1cdb2596649c2fd3c622144847901e43eaa8ebda Mon Sep 17 00:00:00 2001 From: chris Date: Tue, 9 Dec 2025 14:21:35 +0100 Subject: [PATCH] =?UTF-8?q?ha4=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../inspectionProfiles/profiles_settings.xml | 6 + .idea/misc.xml | 7 + .idea/prog a 3.iml | 7 + .idea/vcs.xml | 6 + .idea/workspace.xml | 254 ++++++++++++++++++ Hausaufgaben/Ha4/K-Länge.py | 3 + Hausaufgaben/Ha4/UndoDoodle.py | 58 ++++ Hausaufgaben/Ha4/args.py | 6 + Hausaufgaben/Ha4/timing-Decorator.py | 24 ++ 9 files changed, 371 insertions(+) create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/prog a 3.iml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml create mode 100644 Hausaufgaben/Ha4/K-Länge.py create mode 100644 Hausaufgaben/Ha4/UndoDoodle.py create mode 100644 Hausaufgaben/Ha4/args.py create mode 100644 Hausaufgaben/Ha4/timing-Decorator.py 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..6d3cbac --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/prog a 3.iml b/.idea/prog a 3.iml new file mode 100644 index 0000000..0070e87 --- /dev/null +++ b/.idea/prog a 3.iml @@ -0,0 +1,7 @@ + + + + + \ 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/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..fec9282 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,254 @@ + + + + + + + + + + + + + + + + + + + + + + { + "associatedIndex": 7 +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1760449575234 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Hausaufgaben/Ha4/K-Länge.py b/Hausaufgaben/Ha4/K-Länge.py new file mode 100644 index 0000000..3e07cc8 --- /dev/null +++ b/Hausaufgaben/Ha4/K-Länge.py @@ -0,0 +1,3 @@ +words = ["Apfel", "Banane", "Kirsche", "Kiwi", "Melone"] +pri=sum(len(word) for word in words if word.startswith("K")) +print(pri) \ No newline at end of file diff --git a/Hausaufgaben/Ha4/UndoDoodle.py b/Hausaufgaben/Ha4/UndoDoodle.py new file mode 100644 index 0000000..6061998 --- /dev/null +++ b/Hausaufgaben/Ha4/UndoDoodle.py @@ -0,0 +1,58 @@ +import pygame +from game import Game + +class DrawGame(Game): + def __init__(self): + super().__init__("Zeichenprogramm", fps=60, size=(800, 600)) + self.state = [] + self.history = [] + self.drawing = False + self.current_stroke = [] + + def handle_event(self, event): + if event.type == pygame.QUIT: + return False + + elif event.type == pygame.MOUSEBUTTONDOWN and event.button == 1: + self.drawing = True + self.current_stroke = [event.pos] + + elif event.type == pygame.MOUSEBUTTONUP and event.button == 1: + if self.drawing and len(self.current_stroke) > 1: + self.push_history() + new_state = [stroke[:] for stroke in self.state] + new_state.append(self.current_stroke[:]) + self.state = new_state + self.drawing = False + self.current_stroke = [] + + elif event.type == pygame.MOUSEMOTION and self.drawing: + self.current_stroke.append(event.pos) + + elif event.type == pygame.KEYDOWN and event.key == pygame.K_BACKSPACE: + if self.history: + self.state = self.history.pop() + + return True + + def push_history(self): + snapshot = [stroke[:] for stroke in self.state] + self.history.append(snapshot) + if len(self.history) > 5: + self.history.pop(0) + + def draw_game(self): + self.screen.fill((255, 255, 255)) + + for stroke in self.state: + if len(stroke) > 1: + pygame.draw.lines(self.screen, (0, 0, 0), False, stroke, 2) + + if self.drawing and len(self.current_stroke) > 1: + pygame.draw.lines(self.screen, (0, 0, 0), False, self.current_stroke, 2) + + pygame.display.flip() + + +if __name__ == "__main__": + DrawGame().run() diff --git a/Hausaufgaben/Ha4/args.py b/Hausaufgaben/Ha4/args.py new file mode 100644 index 0000000..a936b71 --- /dev/null +++ b/Hausaufgaben/Ha4/args.py @@ -0,0 +1,6 @@ +t = (1, 2, 3) + +print(t) +print(*t) +print(t, 4) +print(*t, 4) diff --git a/Hausaufgaben/Ha4/timing-Decorator.py b/Hausaufgaben/Ha4/timing-Decorator.py new file mode 100644 index 0000000..50ad02d --- /dev/null +++ b/Hausaufgaben/Ha4/timing-Decorator.py @@ -0,0 +1,24 @@ +from time import perf_counter as pfc +from functools import wraps + +def timing(func): + @wraps(func) + def wrapper(*args, **kwargs): + start = pfc() + result = func(*args, **kwargs) + end = pfc() + print(f"Dauer: {end - start:.4f}s") + return result + return wrapper + + +@timing +def meine_funktion(n): + total = 0 + for i in range(n): + total += i + return total + + +ergebnis = meine_funktion(1000000) +print("Ergebnis:", ergebnis) \ No newline at end of file