-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrectangle.py
93 lines (62 loc) · 1.64 KB
/
rectangle.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
from OpenGL.GL import*
from OpenGL.GLU import*
from OpenGL.GLUT import*
def clearscreen():
glClearColor(0.0, 0.0, 0.0, 0.0)
gluOrtho2D(-100, 100, -100, 100)
glClear(GL_COLOR_BUFFER_BIT)
glColor3f(0.0, 0.0, 1.0)
glPointSize(5.0)
def setpixel(edges,points):
glBegin(GL_LINES)
for e in edges:
for v in e:
glVertex2fv(points[v])
glEnd()
glFlush()
def rectangle(x1,y1,x2,y2):
edges = [
[0,1],
[1,2],
[2,3],
[3,0]
]
points =[
[x1,y2],
[x2,y2],
[x2,y1],
[x1,y1]
]
hana = (1.0,0.0,0.0)
setpixel(edges,points)
# -------line--------------------------------
# def line(x1,y1,x2,y2):
# edges = [
# [0,1],
# ]
# points=[
# [x1,y1],
# [x2,y2]
# ]
# setpixel(edges,points)
def main():
choice=0
while(choice!=2):
choice=int(input("Enter\n\t1.Plot a line \n\t2.exit\n"))
if choice==1:
x1=float(input('x1 Coordinate:'))
x2=float(input('x2 Coordinate:'))
y1=float(input("y1 Coordinate:"))
y2=float(input("y2 Coordinate:"))
glutInit()
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB)
glutInitWindowSize(500,500)
glutInitWindowPosition(200,200)
glutCreateWindow("Line using Midpoint Algorithm")
glutDisplayFunc(lambda: rectangle(x1, y1, x2, y2))
glutIdleFunc(lambda: rectangle(x1, y1, x2, y2))
clearscreen()
glutMainLoop()
else:
print("Invalid Choice")
main()