lab_iteration/tile_grid.py

43 lines
1.6 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.
(It starts with x origin, and creates a square, and the same size of the square will be copied and generated until the given width is all used for drawing. Then, it comes back to the x origin and then go up one unit and repeats the same process to make a set of squares. Basically we have a two layer of a set of squares, and then it keeps going until it hits the full given height. The wiggly ziggly pattern for the title is added for each tile, and this is done by using tile fuction.The whole process looks like a putting tites or blocks from the bottom and adding more layers)
"""
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)