Reconceptualized lab

This commit is contained in:
Chris Proctor 2023-07-18 17:55:04 -04:00
parent d25645282a
commit cd129bb015
6 changed files with 142 additions and 2 deletions

View File

@ -4,10 +4,9 @@ version = "0.1.0"
description = ""
authors = ["Chris Proctor <chris@chrisproctor.net>"]
readme = "README.md"
packages = [{include = "lab_iteration"}]
[tool.poetry.dependencies]
python = "^3.11"
python = "^3.10"
[build-system]

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)

16
square.py Normal file
View File

@ -0,0 +1,16 @@
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)

43
tile.py Normal file
View File

@ -0,0 +1,43 @@
from turtle import *
def draw_tile(size):
"Draws one tile, which can be repeated to form a pattern."
color("grey")
square(size)
forward(size/2)
color("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)
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`"
forward(size)
left(90)
forward(size)
left(90)
forward(size)
left(90)
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)

10
tile_drawing.py Normal file
View File

@ -0,0 +1,10 @@
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)

41
tile_grid.py Normal file
View File

@ -0,0 +1,41 @@
from turtle import *
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)
forward(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()
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)
left(90)
pendown()
def move_up_one_row(tile_size):
"Moves the turtle up one row"
penup()
left(90)
forward(tile_size)
right(90)
pendown()