Files
lab_iteration/tile_grid.py
angelotr 49db8a57a8 A few changes I did in tile.py was I added color to my draw_tile() function and added a sqwiggle to make my tile unique. This made a cross pattern tile with a sqwiggle inside the tile.
Checkpoint 3:
When writing my own programs I think I would try to use docstrings more. When writing programs I normally use the hashtag which has become muscle memory for me but I will try to use docstring because it looks cleaner and more effective.
2025-09-14 23:31:17 -04:00

43 lines
1.2 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.
The draw_tile_grid function draws a grid of tiles by repeatedly calling a given tile-drawing function across each row and column, moving the turtle to the correct position after each tile and row until the whole grid is complete.
"""
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)