pentagone.py

Created by schraf

Created on September 27, 2023

1.64 KB

```from math import *
from turtle import *

def dist(a, b):
return sqrt((a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2)

def angle(a, b):
return degrees(atan2(b[1] - a[1], b[0] - a[0]))

def point(a):
penup()
goto(a)
pendown()
pensize(4)
goto(position())
pensize(1)

def segment(a, b, coul, dash=True):
color(coul)
pensize(1)
r = dist(a, b)
penup()
point(a)
for i in range(r):
penup() if i % 5 and dash else pendown()
fd(1)
point(b)

def arc(a, b, c, w, coul):
color(coul)
pensize(w)
bc = dist(b, c)
ac = dist(a, c)
ab = dist(a, b)
u = angle(a, b)
t = degrees(acos((ac * ac + ab * ab - bc * bc) / (2 * ac * ab)))
penup()
goto(b)
pendown()
circle(int(ab), t)

def avance(a, b, d):
penup()
goto(a)
fd(d)
pendown()
pensize(4)
goto(position())
pensize(1)

def cercle(a, b, r, coul):
color(coul)
avance(a, b, r)
b = position()
segment(a, b, coul)
p = position()
point(p)
circle(int(r))

speed(1)
cercle((0, 0), (100, 0), 100, "grey")
segment((100, 0), (-100, 0), "grey")
cercle((-100, 0), (0, 0), 100, "purple")
a, b = (-50, sqrt(3) * 50), (-50, -sqrt(3) * 50)
segment(a, b, "blue")
point((-50, 0))
segment((0, 100), (0, -100), "blue")
point((0, 0))