-
Notifications
You must be signed in to change notification settings - Fork 0
/
dda.py
57 lines (52 loc) · 1.26 KB
/
dda.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
import OpenGL
from OpenGL.GL import *
from OpenGL.GLUT import *
from OpenGL.GLU import *
def clearScreen():
glClearColor(1.0, 1.0, 1.0, 1.0)
gluOrtho2D(-1.0, 1.0,-1.0,1.0)
def plotting():
print('Enter coordinates for initial point:')
x1 = int(input('x coordinate: '))
y1 = int(input('y coordinate: '))
print('Enter coordinates for final point:')
x2 = int(input('x coordinate: '))
y2 = int(input('y coordinate: '))
if abs(x2-x1) > abs(y2-y1):
l = abs(x2-x1)
else:
l = abs(y2-y1)
dx = (x2-x1)/l
dy = (y2-y1)/l
x = x1
y = y1
glClear(GL_COLOR_BUFFER_BIT)
glColor3f(0.0,0.0,0.0)
glPointSize(5.0)
glBegin(GL_POINTS)
glVertex2f(x1/100, y1/100)
for i in range(l):
x = x + dx
y = y + dy
glVertex2f(x/100, y/100)
glVertex2f(x2/100, y2/100)
glEnd()
def plot():
plotting()
glColor3f(0.0,0.0,0.0)
glPointSize(5.0)
glBegin(GL_LINES)
glVertex2f(0.0, 1.0)
glVertex2f(0.0, -1.0)
glVertex2f(-1.0, 0.0)
glVertex2f(1.0, 0.0)
glEnd()
glFlush()
glutInit()
glutInitDisplayMode(GLUT_RGB)
glutCreateWindow("Line_DDA")
glutInitWindowSize(100, 100)
glutInitWindowPosition(100, 100)
glutDisplayFunc(plot)
clearScreen()
glutMainLoop()