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.
43 lines
1.1 KiB
Python
43 lines
1.1 KiB
Python
# tile_grid.py
|
|
# ------------
|
|
# By MWC Contributors
|
|
#
|
|
# Implements `draw_tile_grid`, which draws a grid of tiles.
|
|
|
|
from turtle import *
|
|
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.
|
|
|
|
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):
|
|
tile_function(tile_size)
|
|
fly(tile_size)
|
|
return_to_x_origin(tile_size, width)
|
|
move_up_one_row(tile_size)
|
|
return_to_y_origin(tile_size, height)
|
|
|
|
def return_to_x_origin(tile_size, width):
|
|
"After drawing a row of tiles, returns the turtle to the starting x position"
|
|
fly(-1 * tile_size * width)
|
|
|
|
def return_to_y_origin(tile_size, height):
|
|
"After drawing all rows of tiles, returns the turtle to the starting y position"
|
|
right(90)
|
|
fly(tile_size * height)
|
|
left(90)
|
|
|
|
def move_up_one_row(tile_size):
|
|
"Moves the turtle up one row"
|
|
left(90)
|
|
fly(tile_size)
|
|
right(90)
|
|
|
|
|
|
|
|
|
|
|