-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPython_Turtle_Metric_Ruler_Box_GUI.py
More file actions
133 lines (115 loc) · 3.94 KB
/
Python_Turtle_Metric_Ruler_Box_GUI.py
File metadata and controls
133 lines (115 loc) · 3.94 KB
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
##With user input GUI, have Turtle create metric_ruler with (n) length
##representing large, medium, and fine ruler ticks. Will need
##conditionals with logic to choose 1(3) tick sizes based on tick value.
##Using metric_ruler, create a square, with each side being a ruler.
##Must use helper functions
################Modules##############
import turtle
########Turtle & Screen Setup########
'''create screen'''
wn = turtle.Screen()
'''set screen color to black'''
wn.bgcolor("black")
'''set screen size to size of user monitor'''
wn.setup(width=1.00, height=1.00, startx=None, starty=None)
'''create turtle'''
alex = turtle.Turtle()
'''set turtle to white'''
alex.color('white')
'''set turtle run speed to 0, which is fastest possible without hiding movement and
simply printing the output'''
alex.speed(0)
############GUI Input################
'''User GUI input set to integer'''
n = int(wn.numinput('Ruler Length Input','How long would you like the ruler to be? ',10,minval=10, maxval=150))
############Functions################
def ruler_values(t,i):
'''write value of hash mark on ruler'''
t.right(90)
t.pu()
t.forward(15)
t.pd()
t.write(str(i))
t.pu()
t.backward(15)
t.pd()
t.left(180)
def tens_hash(t,i):
'''make hash mark for non-terminating tens place'''
t.forward(20)
t.backward(20)
t.right(90)
t.forward(5)
def tens_last_hash(t,i):
'''make hash mark for terminating tens place'''
t.forward(20)
t.backward(20)
t.right(90)
def fives_hash(t,i):
'''make hash mark for non-terminating fives place'''
t.forward(10)
t.backward(10)
t.right(90)
t.forward(5)
def fives_last__hash(t,i):
'''make hash mark for terminating fives place'''
t.forward(10)
t.backward(10)
t.right(90)
def small_hash(t,i):
'''make hash mark for non-terminating non 5s and 10s place'''
t.left(90)
t.forward(1)
t.backward(1)
t.right(90)
t.forward(5)
def small_last_hash(t,i):
'''make hash mark for terminating non 5s and 10s place'''
t.left(90)
t.forward(1)
t.backward(1)
t.right(90)
def ruler_tics(t,n):
'''create 3 sizes of ruler tics based on 10s, 5s, and inbetweens'''
for i in range(n+1):
if i % 10 == 0 and i < n:
'''all 10s tic marks that are not the last tic on the ruler'''
ruler_values(t,i)
tens_hash(t,i)
elif i % 10 == 0:
'''last tic on ruler. turn turt to start onactula ruler to make things even all around'''
ruler_values(t,i)
tens_last_hash(t,i)
elif i % 5 == 0 and i < n:
'''all 5s tic marks that are not the last tic on the ruler'''
ruler_values(t,i)
fives_hash(t,i)
elif i % 5 == 0:
'''last tic on ruler. turn turt to start onactula ruler to make things even all around'''
ruler_values(t,i)
fives_last__hash(t,i)
elif i < n:
'''all non 5s and non 10s tic marks that are not the last tic on the ruler'''
small_hash(t,i)
else:
'''last tic on ruler. turn turt to start onactula ruler to make things even all around'''
small_last_hash(t,i)
def ruler_square(t,n):
'''start turtle in position that leaves box centered'''
t.home()
'''to make ruler box centered, need to move turtle backward and down by half the user input (n).
However, tic marks are set with a distance of 5 "lengths", which means the user input must first
be multiplied by 5.'''
a = (n*5)/2
t.pu()
t.backward(a)
t.right(90)
t.forward(a)
t.left(90)
t.pd()
'''create a square using the ruler function above'''
for i in range(4):
ruler_tics(t,n)
t.left(90)
######################Call##############
ruler_square(alex,n)