-
Notifications
You must be signed in to change notification settings - Fork 0
/
flag.py
76 lines (52 loc) · 1.31 KB
/
flag.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
from flag_utils import *
width = 720
height = 480
numstar = 4
pw = 16 # pw,ph control size of points
ph = 60
npoint = 6 # num points on a star
barheight = 80
starRGB = [ 1, 0, 0] # red
barRGB = [.702, .867, .949] # light-blue
backgroundRGB = [ 1, 1, 0] # white
def setcolor(rgb):
setrgbcolor(*rgb)
def background():
setcolor(backgroundRGB)
rectfill(0,0,width,height)
def bars():
moveto(0, 120)
rlineto(width, 0)
moveto(0, 360)
rlineto(width, 0)
setlinewidth(barheight)
setcolor(barRGB)
stroke()
def point():
"draw one point in a star (a triangle)"
moveto(-pw, 0)
rlineto(pw, ph)
rlineto(pw, -ph)
def star():
"draw one star"
degrees = 360 / float(npoint)
for i in range(npoint):
point()
rotate(degrees)
def stars():
# compute horiz distance between stars
# (equally spaced with pad 10 on both sides)
#
sdist = (width - 20)/(numstar+1)
# move to first:
translate(10+sdist, height/2)
for i in range(numstar):
star()
translate(sdist,0)
setcolor(starRGB)
fill()
if __name__ == "__main__":
background()
bars()
stars()
write_png("/tmp/py-flag.png", globals())