# celtique.py

Created by schraf

Created on September 27, 2023

1.52 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 segment(a, b, coul):
pensize(1)
r = dist(a, b)
penup()
goto(a)
color(coul)
for i in range(r):
penup() if i % 5 else pendown()
fd(1)

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)

pt = [(0, -100)]
speed(1)
penup()
goto(pt[0])
pendown()

for _ in range(6):
pensize(1)
circle(100, 60)
pensize(4)
goto(position())
pt.append(position())

r = dist(pt[0], pt[2])
pa = []

for i in range(3):
segment(pt[2 * i + 2], pt[(2 * i + 5) % 6], "grey")
for i in range(3):
segment(pt[2 * i], pt[(2 * i + 2) % 6], "red")
arc(pt[2 * i], pt[2 * i + 2], pt[(2 * i + 4) % 6], 2, "red")
for i in range(3):
avance(pt[2 * i + 1], pt[(2 * i + 4) % 6], 200 - r)
p = position()
segment(p, pt[2 * i + 2], "blue")
arc(p, pt[2 * i + 2], pt[2 * i], 1, "blue")
for i in range(3):
avance(pt[2 * i + 2], (0, 0), 30)
pa.append(position())
for i in range(3):
avance(pt[2 * i + 1], pt[(2 * i + 4) % 6], 50)
p = position()
segment(p, pa[i], "purple")
arc(p, pa[i], pa[(i + 2) % 3], 1, "purple")

hideturtle()```