-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdda.py
75 lines (47 loc) · 966 Bytes
/
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import matplotlib.pyplot as plt
import cv2
import time
start_time = time.time()
# Titik awal
x1 = 1
y1 = 7
# Titik Akhir
x2 = 7
y2 = 15
dy = y2-y1
dx = x2-x1
step = dx if dx > dy else dy
xInc = dx / step
yInc = dy / step
x=x1
y=y1
len=y2+x2
# x axis value list.
x_number_list = []
x_number_list.append(x1)
# y axis value list.
y_number_list = []
y_number_list.append(y1)
for i in range(1,len):
x = x + xInc
y = y + yInc
xBulat=int(x)
yBulat=int(y)
x_number_list.append(xBulat)
y_number_list.append(yBulat)
if(x>=x2 and y>=y2):
break
end_time = time.time()
delta_time = end_time-start_time
print("Execution Time : ",delta_time," ms")
from guppy import hpy
h = hpy()
print (h.heap())
# Draw point based on above x, y axis values.
plt.scatter(x_number_list, y_number_list, s=10)
# Set chart title.
plt.title("Algoritma DDA")
# Set x, y label text.
plt.xlabel("X")
plt.ylabel("Y")
plt.show()