generated from mwc/lab_iteration
Coucou! Ok so making the tile was fun and took me some "productive struggling" to get there. But I made something nice! I think as feedback for next year I would add options or examples of other tiles (without explanation) so students can get a little inspired. The squiggle was a little bit intimidating ngl. Okay and concerning docstrings: love them. It makes reading code way more clear! What is the intention of the def or function etc.
82 lines
1.4 KiB
Python
82 lines
1.4 KiB
Python
from turtle import *
|
|
import math
|
|
|
|
def draw_tile(size):
|
|
"Draws one tile, which can be repeated to form a pattern."
|
|
draw_tile_outline(size)
|
|
draw_cross(size)
|
|
draw_triangle(size)
|
|
draw_circle(size)
|
|
|
|
def draw_tile_outline(size):
|
|
pencolor("#dddddd")
|
|
square(size)
|
|
|
|
def draw_cross(size):
|
|
pencolor("blue")
|
|
fly(size/2)
|
|
left(90)
|
|
fly(size/4)
|
|
right(90)
|
|
cross(size/4)
|
|
right(90)
|
|
fly(size/4)
|
|
right(90)
|
|
fly(size/2)
|
|
right(180)
|
|
|
|
def draw_triangle(size):
|
|
pencolor("red")
|
|
fly(size/8)
|
|
left(90)
|
|
fly(size/8)
|
|
right(90)
|
|
triangle(size/4)
|
|
right(90)
|
|
fly(size/8)
|
|
right(90)
|
|
fly(size/8)
|
|
right(180)
|
|
|
|
def draw_circle(size):
|
|
pencolor("gold")
|
|
fly(size/2.5)
|
|
left(90)
|
|
fly(size/1.5)
|
|
right(90)
|
|
circle(size/8)
|
|
right(90)
|
|
fly(size/1.5)
|
|
right(90)
|
|
fly(size/2.5)
|
|
right(180)
|
|
|
|
def fly(distance):
|
|
"Moves without drawing."
|
|
penup()
|
|
forward(distance)
|
|
pendown()
|
|
|
|
def square(size):
|
|
"Draws a square of side length `size`"
|
|
for side in range(4):
|
|
forward(size)
|
|
left(90)
|
|
|
|
def triangle(size):
|
|
"Draws a triangle with side length `size`"
|
|
for side in range(3):
|
|
forward(size)
|
|
left(120)
|
|
|
|
def cross(size):
|
|
"Draws a cross in invisible square with side length `size`"
|
|
left(45)
|
|
forward(size*math.sqrt(2))
|
|
right(45)
|
|
fly(-size)
|
|
right(45)
|
|
forward(size*math.sqrt(2))
|
|
left(45)
|
|
fly(-size)
|