← RU Pythoncursus

Uitwerking: Turtlegraphics

import turtle

turtle.penup()
turtle.setposition(-150, 0)
turtle.pendown()
turtle.forward(100)
turtle.left(90)
turtle.forward(100)
turtle.left(90)
turtle.forward(100)
turtle.left(90)
turtle.forward(100)
turtle.left(90)

turtle.penup()
turtle.setposition(50, 0)
turtle.pendown()

turtle.forward(100)
turtle.left(90)
turtle.forward(100)
turtle.left(90)
turtle.forward(100)
turtle.left(90)
turtle.forward(100)
turtle.left(90)

sq_size = int(input('Hoe groot moet het vierkant zijn? '))

turtle.penup()
turtle.setposition(-0.5 * sq_size, -1 * sq_size - 50)
turtle.pendown()

color = input('Welke kleur moet het vierkant zijn? ')
color = {'rood':'red',
         'blauw':'blue',
         'groen':'green',
         'geel':'yellow',
         'paars':'purple'}[color]
turtle.fillcolor(color)

color = input('En de randjes? ')
color = {'rood':'red',
         'blauw':'blue',
         'groen':'green',
         'geel':'yellow',
         'paars':'purple'}[color]
turtle.pencolor(color)

turtle.begin_fill()

turtle.forward(sq_size)
turtle.left(90)
turtle.forward(sq_size)
turtle.left(90)
turtle.forward(sq_size)
turtle.left(90)
turtle.forward(sq_size)
turtle.left(90)

turtle.end_fill()

turtle.done()