From c44bc186bd7bc10e3c026b19dc7204b5a9d7a8b7 Mon Sep 17 00:00:00 2001 From: bpotocki Date: Fri, 23 Jan 2026 19:03:48 +0000 Subject: [PATCH] Initial commit --- .commit_template | 24 ++++++++++++++++++++++++ .gitignore | 2 ++ drawtiles.py | 26 ++++++++++++++++++++++++++ pyproject.toml | 16 ++++++++++++++++ ranges.py | 31 +++++++++++++++++++++++++++++++ square.py | 17 +++++++++++++++++ tile.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ tile_grid.py | 42 ++++++++++++++++++++++++++++++++++++++++++ uv.lock | 22 ++++++++++++++++++++++ 9 files changed, 224 insertions(+) create mode 100644 .commit_template create mode 100644 .gitignore create mode 100644 drawtiles.py create mode 100644 pyproject.toml create mode 100644 ranges.py create mode 100644 square.py create mode 100644 tile.py create mode 100644 tile_grid.py create mode 100644 uv.lock 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/.gitignore b/.gitignore new file mode 100644 index 0000000..6a4dae1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.DS_Store +__pycache__ 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/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..004620b --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,16 @@ +[project] +name = "lab-iteration" +version = "5.0.0" +description = "" +authors = [{ name = "Chris Proctor", email = "chris@chrisproctor.net" }] +requires-python = ">=3.10,<4.0" +readme = "README.md" +license = { text = "MIT" } +dependencies = ["superturtle (>=0.2.0,<0.3.0)"] + +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" + +[tool.uv] +package = false diff --git a/ranges.py b/ranges.py new file mode 100644 index 0000000..2fa00d7 --- /dev/null +++ b/ranges.py @@ -0,0 +1,31 @@ +# ranges.py +# --------- +# By MWC Contributors + +def print_all_numbers(maximum): + "Prints all integers from 0 to maximum." + for number in range(maximum): + print(number) + +def print_even_numbers(maximum): + "Prints all even integers from 0 to maximum." + pass + +def print_odd_numbers(maximum): + "Prints all odd integers from 0 to maximum." + pass + +def print_multiples_of_five(maximum): + "Prints all integers which are multiples of five from 0 to maximum." + pass + +chosen_maximum = int(input("Choose a number: ")) +print(f"All numbers from 0 to {chosen_maximum}") +print_all_numbers(chosen_maximum) +print(f"All even numbers from 0 to {chosen_maximum}") +print_even_numbers(chosen_maximum) +print(f"All odd numbers from 0 to {chosen_maximum}") +print_odd_numbers(chosen_maximum) +print(f"All multiples of 5 from 0 to {chosen_maximum}") +print_multiples_of_five(chosen_maximum) + diff --git a/square.py b/square.py new file mode 100644 index 0000000..f1fb2a2 --- /dev/null +++ b/square.py @@ -0,0 +1,17 @@ +from turtle import * + +def square(side_length): + forward(side_length) + right(90) + forward(side_length) + right(90) + forward(side_length) + right(90) + forward(side_length) + right(90) + +sizes = [20, 40, 60, 80, 100] +for size in sizes: + square(size) +input() + diff --git a/tile.py b/tile.py new file mode 100644 index 0000000..697cf8e --- /dev/null +++ b/tile.py @@ -0,0 +1,44 @@ +from turtle import * + +def draw_tile(size): + "Draws one tile, which can be repeated to form a pattern." + draw_tile_outline(size) + draw_squiggle(size) + +def draw_tile_outline(size): + pencolor("#dddddd") + square(size) + +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/4) + left(90) + fly(size) + left(90) + +def fly(distance): + "Moves without drawing." + penup() + forward(distance) + pendown() + +def square(size): + "Draws a square of side length `size`" + for side in range(4): + forward(size) + left(90) + +def quarter_arc_right(radius): + "Draws a quarter of an arc, turning to the right." + circle(-radius, 90) + +def quarter_arc_left(radius): + "Draws a quarter of an arc, turning to the left." + circle(radius, 90) diff --git a/tile_grid.py b/tile_grid.py new file mode 100644 index 0000000..72a0f43 --- /dev/null +++ b/tile_grid.py @@ -0,0 +1,42 @@ +# 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. + + (Your explanation here.) + """ + 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) + + + + + diff --git a/uv.lock b/uv.lock new file mode 100644 index 0000000..c1c6fe0 --- /dev/null +++ b/uv.lock @@ -0,0 +1,22 @@ +version = 1 +requires-python = ">=3.10, <4.0" + +[[package]] +name = "lab-iteration" +version = "5.0.0" +source = { virtual = "." } +dependencies = [ + { name = "superturtle" }, +] + +[package.metadata] +requires-dist = [{ name = "superturtle", specifier = ">=0.2.0,<0.3.0" }] + +[[package]] +name = "superturtle" +version = "0.2.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/6a/92/126ebdb094cce3d058746c99148acb2fb3a132998d69f2945f344e837d04/superturtle-0.2.0.tar.gz", hash = "sha256:807fb419c1dba9cb809a22a68e72c0193bdeed4a9326eb36ad940b2a7ff6ac04", size = 9611 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/bf/a6/221c4dab508d0f2c9c80fe89cc16b4b1df8be98a7458d48cf298f1d993ba/superturtle-0.2.0-py3-none-any.whl", hash = "sha256:ca3a31be3259387b4490846adbf64502acc9d23472912cc43497ab170e89f506", size = 11177 }, +]