generated from mwc/project_drawing
Somewhere I got stuck was when I had to figure out how to turn around to draw more squares. A strategy I used to get un-stuck was trial and error until I got the turtle to rotate in the right way. Something I want to learn more about is how to do the same pattern but with different shapes. I challenged myself in completing this project in under 100 lines of code, and I succeeded with the help of defining and iterations.
86 lines
1.5 KiB
Python
86 lines
1.5 KiB
Python
# drawing.py
|
|
# ----------
|
|
# By Kayden
|
|
#
|
|
# (Briefly describe what this program does.)
|
|
|
|
from turtle import *
|
|
from math import sqrt
|
|
|
|
def fly(distance):
|
|
"The turtle moves without drawing for a specified distance."
|
|
penup()
|
|
forward(distance)
|
|
pendown()
|
|
|
|
def square(size):
|
|
"This function defines the drawing of a square with an iteration."
|
|
for i in range(4):
|
|
forward(size)
|
|
right(90)
|
|
|
|
def pattern():
|
|
"The function draws a square in a square 3 times."
|
|
left(45)
|
|
square(50)
|
|
fly(5)
|
|
right(90)
|
|
fly(5)
|
|
left(90)
|
|
square(40)
|
|
fly(5)
|
|
right(90)
|
|
fly(5)
|
|
left(90)
|
|
square(30)
|
|
|
|
def rotateright():
|
|
"The turtle draws the pattern then moves and rotates right."
|
|
pattern()
|
|
left(135)
|
|
fly(15)
|
|
right(90)
|
|
fly(70)
|
|
right(90)
|
|
|
|
def rotateleft():
|
|
"The turtle draws the pattern then moves and rotates left."
|
|
pattern()
|
|
right(45)
|
|
fly(55)
|
|
left(90)
|
|
fly(70)
|
|
left(90)
|
|
fly(71)
|
|
left(180)
|
|
|
|
def drawright():
|
|
"The turtle draws squares to the right."
|
|
for i in range(5):
|
|
pattern()
|
|
left(135)
|
|
fly(85)
|
|
right(180)
|
|
|
|
def drawleft():
|
|
"The turtle draws squares to the left."
|
|
for i in range(5):
|
|
pattern()
|
|
right(45)
|
|
fly(57)
|
|
|
|
def draw():
|
|
drawright()
|
|
rotateright()
|
|
drawleft()
|
|
rotateleft()
|
|
|
|
"The turtle starts at a specific point and facing a specific direction."
|
|
penup()
|
|
goto(-180,180)
|
|
pendown()
|
|
left(180)
|
|
for i in range(3):
|
|
draw()
|
|
|
|
input() |