← RU Pythoncursus

Uitwerking: Turtlegraphics

import turtle
from math import sqrt

N = 60

def tekendriehoek(kleur, randkleur):
    turtle.pencolor(randkleur)
    turtle.fillcolor(kleur)

    turtle.begin_fill()
    for _ in range(3):
        turtle.forward(N)
        turtle.left(120)
    turtle.end_fill()

tekendriehoek('blue', 'red')

turtle.penup()
turtle.forward(N)
turtle.pendown()

tekendriehoek('blue', 'green')

turtle.penup()
turtle.forward(N)
turtle.pendown()

tekendriehoek('yellow', 'blue')

turtle.penup()
turtle.forward(-1.5*N)
turtle.left(90)
turtle.forward(0.5*N*sqrt(3))
turtle.left(-90)
turtle.pendown()

tekendriehoek('yellow', 'yellow')

turtle.penup()
turtle.forward(N)
turtle.pendown()

tekendriehoek('red', 'green')

turtle.penup()
turtle.forward(-0.5*N)
turtle.left(90)
turtle.forward(0.5*N*sqrt(3))
turtle.left(-90)
turtle.pendown()

tekendriehoek('green', 'red')

turtle.done()