Initial commit

This commit is contained in:
2026-01-26 02:37:39 +00:00
commit 69a9553023
9 changed files with 224 additions and 0 deletions

24
.commit_template Normal file
View File

@@ -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?

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
.DS_Store
__pycache__

26
drawtiles.py Normal file
View File

@@ -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()

16
pyproject.toml Normal file
View File

@@ -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

31
ranges.py Normal file
View File

@@ -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)

17
square.py Normal file
View File

@@ -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()

44
tile.py Normal file
View File

@@ -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)

42
tile_grid.py Normal file
View File

@@ -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)

22
uv.lock generated Normal file
View File

@@ -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 },
]