-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathBresenham_float.py
More file actions
42 lines (36 loc) · 787 Bytes
/
Bresenham_float.py
File metadata and controls
42 lines (36 loc) · 787 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
37
38
39
40
41
42
def line_br_float(win, p1, p2):
if p1 == p2:
win.image.setPixel(p1[0], p1[1], win.pen.color().rgb())
return
dx = p2[0] - p1[0]
dy = p2[1] - p1[1]
sx = sign(dx)
sy = sign(dy)
dx = abs(dx)
dy = abs(dy)
x = p1[0]
y = p1[1]
change = False
if dy > dx:
temp = dx
dx = dy
dy = temp
change = True
h = dy / dx
e = h - 0.5
i = 1
while i <= dx:
win.image.setPixel(x, y, win.pen.color().rgb())
if e >= 0:
if change is False:
y += sy
else:
x += sx
e -= 1
if e < 0:
if change is False:
x += sx
else:
y += sy
e += h
i+=1