generated from mwc/lab_iteration
CHECKPOINT 3 - tile
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.
This commit is contained in:
69
tile.py
69
tile.py
@@ -1,27 +1,55 @@
|
||||
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_squiggle(size)
|
||||
draw_cross(size)
|
||||
draw_triangle(size)
|
||||
draw_circle(size)
|
||||
|
||||
def draw_tile_outline(size):
|
||||
pencolor("#dddddd")
|
||||
square(size)
|
||||
|
||||
def draw_squiggle(size):
|
||||
forward(size/4)
|
||||
pencolor("black")
|
||||
left(90)
|
||||
quarter_arc_right(size/4)
|
||||
quarter_arc_left(size/4)
|
||||
quarter_arc_left(size/4)
|
||||
quarter_arc_right(size/4)
|
||||
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)
|
||||
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."
|
||||
@@ -35,10 +63,19 @@ def square(size):
|
||||
forward(size)
|
||||
left(90)
|
||||
|
||||
def quarter_arc_right(radius):
|
||||
"Draws a quarter of an arc, turning to the right."
|
||||
circle(-radius, 90)
|
||||
def triangle(size):
|
||||
"Draws a triangle with side length `size`"
|
||||
for side in range(3):
|
||||
forward(size)
|
||||
left(120)
|
||||
|
||||
def quarter_arc_left(radius):
|
||||
"Draws a quarter of an arc, turning to the left."
|
||||
circle(radius, 90)
|
||||
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)
|
||||
|
@@ -10,7 +10,7 @@ from tile import fly
|
||||
def draw_tile_grid(width, height, tile_size, tile_function):
|
||||
"""Draws a (width x height) grid, with tile_function drawn on each tile.
|
||||
|
||||
(Your explanation here.)
|
||||
I actually don't get it... explain it to me, pls! Cause how does it link to the tile file?? Confusing...
|
||||
"""
|
||||
for y in range(height):
|
||||
for x in range(width):
|
||||
|
Reference in New Issue
Block a user