-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDDA_line.py
More file actions
36 lines (31 loc) · 905 Bytes
/
DDA_line.py
File metadata and controls
36 lines (31 loc) · 905 Bytes
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
#DDA line
from graphics import *
import time
def ROUND(a):
return int(a + 0.5)
def drawDDA(x1,y1,x2,y2):
x,y = x1,y1
length = (x2-x1) if (x2-x1) > (y2-y1) else (y2-y1)
dx = (x2-x1)/float(length)
dy = (y2-y1)/float(length)
#print ('x = %s, y = %s' % (((ROUND(x),ROUND(x)))))
win = GraphWin('DDA', 600, 480)
PutPixle(win, ROUND(x),ROUND(x))
for i in range(length):
x += dx
y += dy
#print ('x = %s, y = %s' % (((ROUND(x),ROUND(y)))))
time.sleep(0.01)
PutPixle(win, ROUND(x),ROUND(x))
def PutPixle(win, x, y):
""" Plot A Pixle In The Windows At Point (x, y) """
pt = Point(x,y)
pt.draw(win)
def main():
x1 = int(input("Enter Start X1: "))
y1 = int(input("Enter Start Y1: "))
x2 = int(input("Enter End X2: "))
y2 = int(input("Enter End Y2: "))
drawDDA(x1,y1,x2,y2)
if __name__ == "__main__":
main()