Files
lab_iteration/tile_grid.py
Justin Toombs d7555aef89 Created an arc drawing for each tile.
This was definitely trickier than the previous two examples we looked at, and there was a significant amount of trial
and error to get this functional. Specifically, having the turtle return to its original starting point was tricky as
there was a bug where the turtle would glitch around the screen before settling on its end point, which threw me off for
some time. Thankfully, I just began testing some different combinations one at a time until I achieved the desired outcome.
2023-07-25 12:03:34 -04:00

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.
Uses the tile_size function to create an evenly distributed grid before returning to starting position.
"""
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)