generated from mwc/lab_iteration
	Checkpoint 3: - I will definitely use docstrings in the future. I will use them because they are helpful in showing another person what each function does. Also, when I am debugging my code it will be helpful if I know what each function is supposed to be doing.
		
			
				
	
	
		
			43 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			43 lines
		
	
	
		
			1.3 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.
 | 
						|
 | 
						|
    Line 15 will loop through numbers 0 to the height you give it and save it as y.  Line 16 will loop through numbers 0 to the width you give it and save it as x.  The rest of the function will make the tiles then go back to the starting point.  Then to make more tiles it will use move_up_one_row and continue to make them until the necessary amount of tiles are made.
 | 
						|
    """
 | 
						|
    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)
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 |