diff --git a/.commit_template b/.commit_template new file mode 100644 index 0000000..05b6c62 --- /dev/null +++ b/.commit_template @@ -0,0 +1,24 @@ + + +# ----------------------------------------------------------------- +# Write your entire commit message above this line. +# +# The first line should be a quick description of what you changed. +# Then leave a blank line. +# Then, taking as many lines as you want, answer the questions +# corresponding to your checkpoint. +# +# Checkpoint 1: +# - Was it difficult to figure out how to rewrite square() using +# a for-loop? What strategies did you use to figure it out? +# +# Checkpoint 2: +# - Describe something you understand well, or find interesting, about ranges. +# - Describe something you're still unsure about related to ranges. +# +# Checkpoint 3: +# - Docstrings are meant for humans to read; they don't affect how a program runs. +# When you write your own programs in the future, do you think you'll write +# docstrings? Why or why not? + + diff --git a/drawtiles.py b/drawtiles.py new file mode 100644 index 0000000..d855f01 --- /dev/null +++ b/drawtiles.py @@ -0,0 +1,26 @@ +# drawtiles.py +# ------------ +# By MWC Contributors +# +# Provides a command-line interface for drawing a grid of tiles. +# Run `python drawtiles.py --help` for usage instructions. + +from tile import draw_tile +from tile_grid import draw_tile_grid +from superturtle.movement import no_delay +from argparse import ArgumentParser + +parser = ArgumentParser("python drawtiles.py", description="Draws a grid of tiles.") +parser.add_argument("width", type=int, help="How many tiles across the grid should be") +parser.add_argument("height", type=int, help="How many tiles high the grid should be") +parser.add_argument("size", type=int, help="Side length of each tile") +parser.add_argument("--fast", action="store_true", help="Skip turtle animation and show the result") +args = parser.parse_args() + +if args.fast: + with no_delay(): + draw_tile_grid(args.width, args.height, args.size, draw_tile) +else: + draw_tile_grid(args.width, args.height, args.size, draw_tile) +input() + diff --git a/tile.py b/tile.py index 91425f6..697cf8e 100644 --- a/tile.py +++ b/tile.py @@ -2,17 +2,23 @@ from turtle import * def draw_tile(size): "Draws one tile, which can be repeated to form a pattern." - color("grey") + draw_tile_outline(size) + draw_squiggle(size) + +def draw_tile_outline(size): + pencolor("#dddddd") square(size) - forward(size/2) - color("black") + +def draw_squiggle(size): + forward(size/4) + pencolor("black") left(90) quarter_arc_right(size/4) quarter_arc_left(size/4) quarter_arc_left(size/4) quarter_arc_right(size/4) left(90) - fly(size/2) + fly(size/4) left(90) fly(size) left(90) @@ -25,14 +31,9 @@ def fly(distance): def square(size): "Draws a square of side length `size`" - forward(size) - left(90) - forward(size) - left(90) - forward(size) - left(90) - forward(size) - left(90) + for side in range(4): + forward(size) + left(90) def quarter_arc_right(radius): "Draws a quarter of an arc, turning to the right." diff --git a/tile_drawing.py b/tile_drawing.py deleted file mode 100644 index 95cbe9a..0000000 --- a/tile_drawing.py +++ /dev/null @@ -1,10 +0,0 @@ -from tile import draw_tile -from tile_grid import draw_tile_grid -from superturtle.motion import no_delay - -width = 10 -height = 8 -size = 10 - -draw_tile_grid(width, height, size, draw_tile) - diff --git a/tile_grid.py b/tile_grid.py index 9b37e4c..72a0f43 100644 --- a/tile_grid.py +++ b/tile_grid.py @@ -1,4 +1,11 @@ +# 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. @@ -8,32 +15,26 @@ def draw_tile_grid(width, height, tile_size, tile_function): for y in range(height): for x in range(width): tile_function(tile_size) - forward(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" - penup() - back(tile_size * width) - pendown() + 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" - penup() right(90) - forward(tile_size * height) + fly(tile_size * height) left(90) - pendown() def move_up_one_row(tile_size): "Moves the turtle up one row" - penup() left(90) - forward(tile_size) + fly(tile_size) right(90) - pendown()