Skip to content

Instantly share code, notes, and snippets.

@touatily
Last active October 25, 2022 20:48
Show Gist options
  • Save touatily/1e896b9e6f2414750c69a0945291746c to your computer and use it in GitHub Desktop.
Save touatily/1e896b9e6f2414750c69a0945291746c to your computer and use it in GitHub Desktop.
Olympic games flag
import turtle
import math
def drawCircle(tur, center:tuple, rayon:int, color:str="black", fill:str="white", thickness:int=1):
tur.width(thickness)
tur.up()
tur.color(color, fill)
tur.goto(center[0], center[1] + rayon)
tur.setheading(180)
tur.down()
if fill:
tur.begin_fill()
tur.circle(rayon, 360)
def drawBow(tur, center:tuple, rayon:int, start:int, color:str="black", fill:str="white", thickness:int=1, angle=360):
heading = 180 - start
tur.width(thickness)
tur.up()
tur.color(color, fill)
tur.goto(center[0] + (rayon * math.sin(math.radians(start))),
center[1] + (rayon * math.cos(math.radians(start))))
tur.setheading(heading)
tur.down()
if fill:
tur.begin_fill()
tur.circle(rayon, angle)
def drawRect(tur, xy1: tuple, xy2: tuple, color:str, fill:str):
tur.up()
tur.color(color, fill)
tur.goto(xy1[0], xy1[1])
tur.begin_fill()
tur.down()
tur.goto(xy1[0], xy2[1])
tur.goto(xy2[0], xy2[1])
tur.goto(xy2[0], xy1[1])
tur.goto(xy1[0], xy1[1])
tur.end_fill()
t = turtle.Turtle()
t.speed(1)
B = 600
A = 300
rA = A / 18
rB = B / 27
rayon = 3 * rA
p1 = (-6.5 * rB, 1.5 * rA)
points = [ p1,
(p1[0]+6.5*rB, p1[1]),
(p1[0]+13*rB, p1[1]),
(p1[0]+3.25*rB, p1[1]-3*rA),
(p1[0]+9.75*rB, p1[1]-3*rA),
]
colors = ["#0081C8", "#000000", "#EE334E", "#FCB131", "#00A651"]
angles = [135, 225, 225, 315, 315]
drawRect(t, (-B//2, A//2), (B//2, -A//2), "black", "white")
for p in zip(points, colors):
drawCircle(t, p[0], 3 * rA+5, p[1], "white", 10)
for p in zip(points, angles, colors):
drawBow(t, p[0], 3 * rA+5, p[1], p[2], "white", 10, 180)
t.hideturtle()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment