Created
February 12, 2021 03:02
-
-
Save brentxphillips/0823a3cc0ba71c0f3e9fd47844280bfc to your computer and use it in GitHub Desktop.
Draws a tower of squares
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Brent Phillips | |
# Drawes square tower | |
import turtle as t | |
def goto(x, y): | |
t.up() | |
t.goto(x, y) | |
t.down() | |
def rangebox(move, turn, color="black", fill=False, scale=1): | |
t.color(color) | |
if fill: | |
t.begin_fill() | |
x = range(4) | |
for n in x: | |
t.forward(move*scale) | |
t.forward(move*scale) | |
t.right(turn) | |
if fill: | |
t.end_fill() | |
def boxtower (x, y): | |
base = x+x+x | |
middle = x+x | |
top = x | |
goto(0, 0) | |
rangebox(base, 90, "red") | |
goto (middle, middle) | |
rangebox(middle, 90, "blue") | |
goto(base, base) | |
rangebox(top, 90, "red") | |
goto(0, 0) | |
boxtower(20, 10) | |
t.mainloop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment