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 *
|
from turtle import *
|
||||||
|
import math
|
||||||
|
|
||||||
def draw_tile(size):
|
def draw_tile(size):
|
||||||
"Draws one tile, which can be repeated to form a pattern."
|
"Draws one tile, which can be repeated to form a pattern."
|
||||||
draw_tile_outline(size)
|
draw_tile_outline(size)
|
||||||
draw_squiggle(size)
|
draw_cross(size)
|
||||||
|
draw_triangle(size)
|
||||||
|
draw_circle(size)
|
||||||
|
|
||||||
def draw_tile_outline(size):
|
def draw_tile_outline(size):
|
||||||
pencolor("#dddddd")
|
pencolor("#dddddd")
|
||||||
square(size)
|
square(size)
|
||||||
|
|
||||||
def draw_squiggle(size):
|
def draw_cross(size):
|
||||||
forward(size/4)
|
pencolor("blue")
|
||||||
pencolor("black")
|
fly(size/2)
|
||||||
left(90)
|
|
||||||
quarter_arc_right(size/4)
|
|
||||||
quarter_arc_left(size/4)
|
|
||||||
quarter_arc_left(size/4)
|
|
||||||
quarter_arc_right(size/4)
|
|
||||||
left(90)
|
left(90)
|
||||||
fly(size/4)
|
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)
|
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)
|
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):
|
def fly(distance):
|
||||||
"Moves without drawing."
|
"Moves without drawing."
|
||||||
@@ -35,10 +63,19 @@ def square(size):
|
|||||||
forward(size)
|
forward(size)
|
||||||
left(90)
|
left(90)
|
||||||
|
|
||||||
def quarter_arc_right(radius):
|
def triangle(size):
|
||||||
"Draws a quarter of an arc, turning to the right."
|
"Draws a triangle with side length `size`"
|
||||||
circle(-radius, 90)
|
for side in range(3):
|
||||||
|
forward(size)
|
||||||
|
left(120)
|
||||||
|
|
||||||
def quarter_arc_left(radius):
|
def cross(size):
|
||||||
"Draws a quarter of an arc, turning to the left."
|
"Draws a cross in invisible square with side length `size`"
|
||||||
circle(radius, 90)
|
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):
|
def draw_tile_grid(width, height, tile_size, tile_function):
|
||||||
"""Draws a (width x height) grid, with tile_function drawn on each tile.
|
"""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 y in range(height):
|
||||||
for x in range(width):
|
for x in range(width):
|
||||||
|
Reference in New Issue
Block a user