-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpinwheel2.py
148 lines (121 loc) · 4.02 KB
/
pinwheel2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import turtle
from math import *
def drawSquareFromCenter(turtle, x):
#making my variables
move = x / 2
turtle.penup()
turtle.forward(-move)
turtle.right(90)
turtle.forward(move)
turtle.left(90)
turtle.pendown()
turtle.forward(x)
turtle.left(90)
turtle.forward(x)
turtle.left(90)
turtle.forward(x)
turtle.left(90)
turtle.forward(x)
turtle.left(90)
turtle.penup()
turtle.forward(move)
turtle.left(90)
turtle.forward(move)
turtle.right(90)
def firstSquare(turtle,x):
move = x / 2
turtle.penup()
turtle.forward(move)
turtle.left(90)
turtle.forward(move)
turtle.right(90)
turtle.forward(move)
turtle.left(90)
turtle.forward(move)
turtle.left(90)
turtle.pendown()
turtle.forward(x)
turtle.left(90)
turtle.forward(x)
turtle.left(90)
turtle.forward(x)
turtle.left(90)
turtle.forward(x)
turtle.left(90)
turtle.penup()
turtle.forward(move)
turtle.left(90)
turtle.forward(move)
turtle.right(90)
def backToOrigin(turtle,x):
move = x/2
turtle.forward(move)
turtle.left(90)
turtle.forward(move)
def back2origin(turtle,x):
turtle.left(135)
distance = sqrt(x/2*x/2 + x/2*x/2)
turtle.forward(distance)
turtle.right(135)
def moveToSecondSquare(turtle,x):
turtle.left(45)
hypotenuse = sqrt(x/2*x/2 + x/2*x/2)
turtle.forward(hypotenuse)
turtle.left(45)
def moveToThirdSquare(turtle,size):
x,y = turtle.pos()
destination = (x - (size / 2)), (y - (size / 2))
turtle.setpos(destination)
def moveToLastSquare(turtle,x,y):
delta_x = (y / 2) - (-x / 2)
delta_y = (-y / 2) - (-x / 2)
distance = sqrt(delta_x**2 + delta_y**2)
angle = degrees(atan(int(((y/2)+(x/2))/(y/2))))
turtle.left(angle)
turtle.forward(distance)
def chooseIcon(dave,person):
screen = turtle.Screen()
if(person == "rick"):
image = r"C:\Users\David Ojo\Desktop\Media\Python\CS101\rick.gif"
if(person == "morty"):
image = r"C:\Users\David Ojo\Desktop\Media\Python\CS101\morty.gif"
if(person == "head"):
image = r"C:\Users\David Ojo\Desktop\Media\Python\CS101\head.gif"
if(person == "moonman"):
image = r"C:\Users\David Ojo\Desktop\Media\Python\CS101\moonman.gif"
screen.addshape(image)
dave.shape(image)
def main():
#use user input to get the values for the four squares
size1 = int(input('Enter the number of the first square: '))
size2 = int(input('Enter the number of the second square: '))
size3 = int(input('Enter the number of the third square: '))
size4 = int(input('Enter the number of the fourth square: '))
#create turtle object
dave = turtle.Turtle()
dave.pencolor("green")
dave.speed(4)
''' [draw graphics] '''
#chooseIcon(dave, "rick")
#use custom method to draw the first square by heading to the center
firstSquare(dave,size1)
#move back to the orgin by the reverse of what put me in the center
backToOrigin(dave,size1)
#chooseIcon(dave, "moonman")
#move to second square by rotatinng 45 degrees and going the distance of the hypotenuse
moveToSecondSquare(dave,size2)
#draw square from center
drawSquareFromCenter(dave,size2)
#move back to center by fliping 180 and following the hypotenuse back up to the orgin
back2origin(dave,size2)
#chooseIcon(dave,"morty")
#get current coordinates and set your destination to the center of the third square + curent location
moveToThirdSquare(dave,size3)
#draw square from center
drawSquareFromCenter(dave,size3)
#chooseIcon(dave, "head")
#find the angle that lines up with center of last square and go the distance of the hypoteuse to get there
moveToLastSquare(dave,size3,size4)
#draw square from center
drawSquareFromCenter(dave,size4)
main()