# 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. (The draw_tile_grid function is importing from the tile.py defined functions "draw_tile_outline" and draw_squiggle to repeat the individual elements, tiles. Within draw_tile_grid, you use a "range" to repeat the height and width for size and moving (fly) without drawing. Then using the definition of "return_to_x_origin" and "return_to_y_origin" to the next x and y coordinates to position the pen to draw the next tile or begin the next row. Just as important is "drawtiles.py" file that calls the arguments/parameters for user input of width, height, and size. Although, the if else statement is using the defintion "draw_tile" where the argument prompt is coming from the "tile.py" definition "draw_tile. The 3 python files, drawtiles.py, tile.py, and tile_grid.py are drawing functions from each file without having to repeat the code in each file. Complicated and intricate. It's functional.) """ 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)