generated from mwc/project_drawing
80 lines
1.9 KiB
Python
80 lines
1.9 KiB
Python
# drawing.py
|
|
# ----------
|
|
# By ____(you)___________
|
|
#
|
|
# (Briefly describe what this program does.)
|
|
|
|
from turtle import *
|
|
from superturtle.movement import no_delay
|
|
|
|
# We'll define our functions in terms of units.
|
|
|
|
|
|
|
|
|
|
|
|
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"
|
|
begin_fill()
|
|
for quantity, color in quantities_and_colors:
|
|
fillcolor(color)
|
|
for each_square in range(quantity):
|
|
square(unit)
|
|
forward(unit)
|
|
end_fill()
|
|
|
|
def go_back(unit, quantities_and_colors):
|
|
total = 0
|
|
for quantity, color in quantities_and_colors:
|
|
total += quantity
|
|
right(90)
|
|
forward(unit)
|
|
right(90)
|
|
forward(unit * total)
|
|
left(90)
|
|
left(90)
|
|
|
|
|
|
|
|
drawing_size = 20
|
|
data = [
|
|
[[3, "white"], [5, "black"], [3, "white"]],
|
|
[[3, "white"], [3, "black"], [1, "white"], [1, "black"], [3, "white"]],
|
|
[[3, "white"], [5, "black"], [1, "orange"], [2, "white"]],
|
|
[[3, "white"], [5, "black"], [1, "orange"], [2, "white"]],
|
|
[[3, "white"], [4, "black"], [4, "white"]],
|
|
[[3, "white"], [4, "black"], [4, "white"]],
|
|
[[3, "white"], [4, "black"], [4, "white"]],
|
|
[[3, "black"], [7, "black"], [1, "white"]],
|
|
[[3, "white"], [1, "black"], [2, "white"], [1, "black"], [4, "white"]],
|
|
[[3, "white"], [1, "black"], [2, "white"], [1, "black"], [4, "white"]],
|
|
[[3, "white"], [1, "black"], [2, "white"], [1, "black"], [4, "white"]],
|
|
[[3, "white"], [4, "black"], [4, "white"]],
|
|
[[3, "white"], [1, "orange"], [2, "white"], [1, "orange"], [4, "white"]],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
]
|
|
|
|
with no_delay():
|
|
for row in data:
|
|
row_of_squares(drawing_size, row)
|
|
go_back(drawing_size, row)
|
|
|
|
|
|
go_back
|
|
|
|
input() |