generated from mwc/project_drawing
58 lines
1.5 KiB
Python
58 lines
1.5 KiB
Python
# drawing.py
|
|
# ----------
|
|
# By ____(you)___________
|
|
#
|
|
# (Briefly describe what this program does.)
|
|
|
|
from turtle import *
|
|
|
|
def square(unit):
|
|
"Draws a square of size unit"
|
|
begin_fill()
|
|
for side in range(4):
|
|
forward(unit)
|
|
right(90)
|
|
end_fill()
|
|
|
|
def row_of_squares(unit, quantities_and_colors):
|
|
"Draws a row of squares, one in each color in colors"
|
|
squares_traveled = 0
|
|
for quantity, color in quantities_and_colors:
|
|
fillcolor(color)
|
|
for each_square in range(quantity):
|
|
square(unit)
|
|
forward(unit)
|
|
squares_traveled = squares_traveled + 1
|
|
return_to_baseline(unit, squares_traveled)
|
|
|
|
def return_to_baseline(unit, count):
|
|
right(180)
|
|
penup()
|
|
forward(unit * count)
|
|
left(90)
|
|
forward(unit)
|
|
left(90)
|
|
pendown()
|
|
|
|
drawing_size = 10
|
|
penup()
|
|
goto(-200, 0)
|
|
pendown()
|
|
|
|
data = [
|
|
[[10, "white"]],
|
|
[[4, "white"], [2, "green"], [4, "white"]],
|
|
[[3, "white"], [1, "pink"], [1, "red"], [2, "green"], [3, "white"]],
|
|
[[1, "white"], [1, "green"], [1, "white"], [2, "red"], [2, "green"], [1, "white"], [1, "pink"], [1, "white"]],
|
|
[[1, "white"], [8, "green"], [1, "white"]],
|
|
[[3, "white"], [5, "green"], [2, "white"]],
|
|
[[3, "white"], [4, "green"], [3, "white"]],
|
|
[[2, "white"], [6, "brown"], [2, "white"]],
|
|
[[3, "white"], [4, "brown"], [3, "white"]],
|
|
[[3, "white"], [4, "brown"], [3, "white"]],
|
|
|
|
|
|
]
|
|
|
|
for row in data:
|
|
row_of_squares(drawing_size, row) |