-
Notifications
You must be signed in to change notification settings - Fork 0
/
america.py
185 lines (172 loc) · 4.74 KB
/
america.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
## America
## 9/25/2012
## Usman M.
import turtle
import time
import random
def get_color(color2):
## If color2 equals 1, then make the color white.
if color2 == 1:
r = g = b = 1
return (r, g, b)
## If color2 equals 1, then make the color red.
if color2 == 0:
r = 1
g = 0
b = 0
return (r, g, b)
## If color2 equals 1, then make the color black.
if color2 == 2:
r = 0
g = 0
b = 1
return (r, g, b)
def draw_rectangle(length, height, color):
turtle.up()
x = -150
y = 150
C = height*(7/13)
D = length*(2/5)
L = stripe_width = float(round(height/13,1))
## Draw main rectangle first.
color2 = 0 ## Red flag background.
color = get_color(color2)
turtle.color(color)
turtle.begin_fill()
turtle.setpos(x,y)
turtle.down()
turtle.forward(length)
turtle.right(90)
turtle.forward(height)
turtle.right(90)
turtle.forward(length)
turtle.right(90)
turtle.forward(height)
turtle.end_fill()
## Then draw the stripes.
x1 = -150
y1 = 150-L
## Make sure that the color for the stripes alternate.
for z in range(1,14):
if z%2 == 0: ## If the number is even, its a white stripe.
color2 = 1
color = get_color(color2)
turtle.up()
turtle.speed(100)
turtle.setpos(x1,y1)
turtle.setheading(90)
turtle.down()
turtle.color(color)
turtle.begin_fill()
turtle.forward(L)
turtle.right(90)
turtle.forward(length)
turtle.right(90)
turtle.forward(L)
turtle.right(90)
turtle.forward(length)
turtle.end_fill()
y1 -= L
else: ## If the number is odd, its a red stripe.
color2 = 0
color = get_color(color2)
turtle.up()
turtle.speed(100)
turtle.setpos(x1,y1)
turtle.setheading(90)
turtle.down()
turtle.color(color)
turtle.begin_fill()
turtle.forward(L)
turtle.right(90)
turtle.forward(length)
turtle.right(90)
turtle.forward(L)
turtle.right(90)
turtle.forward(length)
turtle.end_fill()
y1 -= L
## Finally draw the rectangle which contains the stars.
color2 = 2
color = get_color(color2)
x2 = -150+D
y2 = 150.5-C
turtle.up()
turtle.setpos(x2,y2)
turtle.down()
turtle.color(color)
turtle.begin_fill()
turtle.forward(D)
turtle.right(90)
turtle.forward(C)
turtle.right(90)
turtle.forward(D)
turtle.right(90)
turtle.forward(C)
turtle.end_fill()
turtle.up()
## Now draw the stars.
draw_star(-length, height, color)
def draw_star(l, h, color):
## This function and its respective if loops define the rows (5 total).
for z in range(50):
if z < 7:
row = 140
draw_starrows(row)
if z < 14:
row = row - 20
draw_starrows(row)
if z < 21:
row = row - 20
draw_starrows(row)
if z < 28:
row = row - 20
draw_starrows(row)
if z < 35:
row = row - 20
draw_starrows(row)
## This gets the turtle pen out of the way at the very end.
turtle.up()
turtle.setpos(-180,100)
time.sleep(5)
break
def draw_starrows(row):
color2 = 1
color = get_color(color2)
x = -160
y = 150
## This for loop draws 10 stars for each row above (5 total x 10 = 50).
for z in range(10):
x += 15
turtle.up()
turtle.color(color)
turtle.speed(100)
turtle.setpos(x,row)
turtle.begin_fill()
turtle.down()
turtle.forward(6.154)
turtle.left(144)
turtle.forward(6.154)
turtle.left(144)
turtle.forward(6.154)
turtle.left(144)
turtle.forward(6.154)
turtle.left(144)
turtle.forward(6.154)
turtle.left(144)
turtle.end_fill()
def draw_flag():
A = 200
height = int(A)
color = (0,0,0)
draw_rectangle(height*1.9, height, color)
## Dimension notes for easy access.
## length = height*1.9
## C = height*(7/13)
## D = length*(2/5)
## E = F = union_height/10
## G = H = union_length/12
## stripe_width = height/13
## diameter_star = stripe_width*(4/5)
draw_flag()
turtle.bye()