Major updates

This commit is contained in:
Chris Proctor
2023-07-18 18:51:29 -04:00
parent 485f37565f
commit 0172850749
5 changed files with 74 additions and 32 deletions

View File

@@ -1,4 +1,11 @@
# 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.
@@ -8,32 +15,26 @@ def draw_tile_grid(width, height, tile_size, tile_function):
for y in range(height):
for x in range(width):
tile_function(tile_size)
forward(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"
penup()
back(tile_size * width)
pendown()
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"
penup()
right(90)
forward(tile_size * height)
fly(tile_size * height)
left(90)
pendown()
def move_up_one_row(tile_size):
"Moves the turtle up one row"
penup()
left(90)
forward(tile_size)
fly(tile_size)
right(90)
pendown()