-
Notifications
You must be signed in to change notification settings - Fork 6
/
drawPolygon.py
57 lines (50 loc) · 1.04 KB
/
drawPolygon.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
from drawLine import ViewPort,bresenham,drawLine
import sys,random
from graphics import *
'''
100 100
50 0
100 -100
0 -50
-100 -100
-50 0
-100 100
0 50
'''
def drawPoly(vertices,win,color='white'):
vert = vertices.copy()
vert+=[vert[0]]
for i in range(len(vert)-1):
x1,y1,x2,y2 = *vert[i],*vert[i+1]
#print(win,color,x1,y1,x2,y2)
drawLine(win,color,x1,y1,x2,y2)
def main():
vert = []
while(1):
try:
x,y=map(int,input('Next vert?').split())
vert.append((x,y))
except:
print(vert)
break
if(input('Defualt viewPort is (-400 -400, 400 400). Change?(y/Y)')in ('y','Y')):
x,y=map(int,input('viewPort\'s xMax yMax : ').split())
new_view = ViewPort(-x,-y,x,y)
else:
new_view =ViewPort(-400,-400,400,400)
print('ViewPort :',new_view)
pixel = []
filled= []
pixel_dict={}
vert+=[vert[0]]
win = new_view.init_view()
for i in range(len(vert)-1):
pixel+=bresenham(*vert[i],*vert[i+1])
for i in pixel:
x,y= i
win.plot(*i)
pixel_dict[(x,y)]=1
stack=[(0,0)]
input('Exit?')
if __name__=='__main__':
main()