2 files modified
4 files added
New file |
| | |
| | | from turtle import Turtle |
| | | |
| | | class GeoTurtle(Turtle): |
| | | |
| | | def square(self, size:float): |
| | | for _ in range(4): |
| | | self.forward(size) |
| | | self.left(90) |
| | | |
New file |
| | |
| | | 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() |
| | |
| | | #from turtle import Turtle |
| | | import turtle |
| | | |
| | | class Polynomial: |
| | | def __init__(self, *argv: float): |
| | | if len(argv) < 1: |
| | |
| | | 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 |
| | |
| | | from polynomial import Polynomial |
| | | from polynomial import Polynomial, plot_polynomial |
| | | import turtle |
| | | |
| | | EPSILON = 0.001 |
| | | |
| | | def test_polynomial_representation(): |
| | |
| | | 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 |
New file |
| | |
| | | [build-system] |
| | | requires = ["setuptools"] |
| | | build-backend = "setuptools.build_meta" |
| | | |
| | | [project] |
| | | name = "polynomial" |
| | | version = "0.0.1" |
| | | |
| | | |