generated from mwc/lab_iteration
	It was irritating that it didnt count the last number, for example if i gave it 100 counting by 5 it would stop at 95. Maybe. Normally i run solo for everything so i wouldnt find much use but i might use it if i want to share my code with friends or family.
		
			
				
	
	
		
			44 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			44 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.
 | 
						|
 | 
						|
    (This function draws the grid which has the tile pattern inside of it by the user selecting a size and then it maps the grid or
 | 
						|
    pattern that the user wants.)
 | 
						|
    """
 | 
						|
    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)
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 |