Hong-Phuc Bui
10 days ago fd66402c90a63cf8ce455c3614b9160884f74c61
Vorlesung 10.6
2 files modified
4 files added
73 ■■■■■ changed files
geoturtle-inheritance/geoturtle.py 9 ●●●●● patch | view | raw | blame | history
geoturtle-inheritance/plotsquare.py 13 ●●●●● patch | view | raw | blame | history
polymonial/main.py patch | view | raw | blame | history
polymonial/polynomial.py 27 ●●●●● patch | view | raw | blame | history
polymonial/polynomial_test.py 15 ●●●● patch | view | raw | blame | history
polymonial/pyproject.toml 9 ●●●●● patch | view | raw | blame | history
geoturtle-inheritance/geoturtle.py
New file
@@ -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)
geoturtle-inheritance/plotsquare.py
New file
@@ -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()
polymonial/main.py
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
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()
    #test_plot_polynomial()
    pass
polymonial/pyproject.toml
New file
@@ -0,0 +1,9 @@
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"
[project]
name = "polynomial"
version = "0.0.1"