From fd66402c90a63cf8ce455c3614b9160884f74c61 Mon Sep 17 00:00:00 2001
From: Hong-Phuc Bui <hong-phuc.bui@htwsaar.de>
Date: Wed, 11 Jun 2025 16:39:08 +0200
Subject: [PATCH] Vorlesung 10.6

---
 polymonial/polynomial.py            |   27 +++++++++++++
 geoturtle-inheritance/plotsquare.py |   13 ++++++
 polymonial/main.py                  |    0 
 geoturtle-inheritance/geoturtle.py  |    9 ++++
 polymonial/polynomial_test.py       |   15 ++++++-
 polymonial/pyproject.toml           |    9 ++++
 6 files changed, 70 insertions(+), 3 deletions(-)

diff --git a/geoturtle-inheritance/geoturtle.py b/geoturtle-inheritance/geoturtle.py
new file mode 100644
index 0000000..6c2f31c
--- /dev/null
+++ b/geoturtle-inheritance/geoturtle.py
@@ -0,0 +1,9 @@
+from turtle import Turtle
+
+class GeoTurtle(Turtle):
+
+    def square(self, size:float):
+        for _ in range(4):
+            self.forward(size)
+            self.left(90)
+
diff --git a/geoturtle-inheritance/plotsquare.py b/geoturtle-inheritance/plotsquare.py
new file mode 100644
index 0000000..b056268
--- /dev/null
+++ b/geoturtle-inheritance/plotsquare.py
@@ -0,0 +1,13 @@
+from geoturtle import GeoTurtle
+
+anna = GeoTurtle()
+anna.forward(100)
+anna.left(30)
+anna.square(50)
+
+paul = GeoTurtle()
+paul.back(100)
+paul.right(30)
+paul.square(50)
+
+anna.screen.mainloop()
diff --git a/polymonial/main.py b/polymonial/main.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/polymonial/main.py
diff --git a/polymonial/polynomial.py b/polymonial/polynomial.py
index 2ca4f73..5ea6a47 100644
--- a/polymonial/polynomial.py
+++ b/polymonial/polynomial.py
@@ -1,3 +1,6 @@
+#from turtle import Turtle
+import turtle
+
 class Polynomial:
     def __init__(self, *argv: float):
         if len(argv) < 1:
@@ -47,4 +50,26 @@
             coe.append(f'{c}')
         return ' '.join(coe)
 
-
+def plot_polynomial(t:turtle.Turtle, p:Polynomial, width=500, height=500):
+    x_value = []
+    y_value = []
+    n = 9
+    delta = 2 * width / (n-1)
+    x0 = -width
+    for i in range(0, n):
+        y0 = p.evaluate(x0)[0]
+        x_value.append(x0)
+        y_value.append(y0)
+        print(x0, y0)
+        x0 = x0 + delta
+    y_min = min(y_value)
+    y_max = max(y_value)
+    m = height - (2*height)/(y_max - y_min) * y_max
+    w = lambda y : 2*height/(y_max - y_min) * y + m
+    for i in range(0, n):
+        x = x_value[i]
+        y = y_value[i]
+        y = w(y)
+        print(x,y)
+        t.goto(x,y)
+    pass
diff --git a/polymonial/polynomial_test.py b/polymonial/polynomial_test.py
index 2fa1f53..7d5dbd9 100644
--- a/polymonial/polynomial_test.py
+++ b/polymonial/polynomial_test.py
@@ -1,4 +1,6 @@
-from polynomial import Polynomial
+from polynomial import Polynomial, plot_polynomial
+import turtle
+
 EPSILON = 0.001
 
 def test_polynomial_representation():
@@ -46,6 +48,15 @@
         assert abs(pc - ec) < EPSILON
 
 
+def GGGGGG_plot_polynomial():
+    p = Polynomial(0, 0, 1)
+    t = turtle.Turtle()
+    width,height = 1000,1000
+    turtle.screensize(width,height)
+    plot_polynomial(t, p, width=width / 2, height=height / 2)
+    t.screen.mainloop()
+
 if __name__ == "__main__":
     #test_evaluate_2()
-    test_polynomial_add()
\ No newline at end of file
+    #test_plot_polynomial()
+    pass
\ No newline at end of file
diff --git a/polymonial/pyproject.toml b/polymonial/pyproject.toml
new file mode 100644
index 0000000..ff8d4c8
--- /dev/null
+++ b/polymonial/pyproject.toml
@@ -0,0 +1,9 @@
+[build-system]
+requires = ["setuptools"]
+build-backend = "setuptools.build_meta"
+
+[project]
+name = "polynomial"
+version = "0.0.1"
+
+

--
Gitblit v1.10.0