-
Notifications
You must be signed in to change notification settings - Fork 5
/
Bresenham_smooth.py
65 lines (57 loc) · 1.3 KB
/
Bresenham_smooth.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
def line_br_smooth(win, p1, p2):
if p1 == p2:
win.image.setPixel(p1[0], p1[1], win.pen.color().rgb())
return
win.pen.setColor(win.color_line)
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]
try:
h = dy / dx
except ZeroDivisionError:
h = 0
isBlack = False
if win.pen.color() == Qt.black:
i_max = 256
isBlack = True
else:
i_max = 100
change = False
if dy > dx:
temp = dx
dx = dy
dy = temp
change = True
if h:
h = 1 / h
h *= i_max
e = i_max/2
w = i_max - h
i = 1
while i <= dx:
if not isBlack:
new = win.pen.color()
new.lighter(100 + e)
win.pen.setColor(new)
win.image.setPixel(x, y, win.pen.color().rgba())
else:
new = QColor()
new.setRgb(0, 0, 0, alpha=255 - e)
win.pen.setColor(new)
win.image.setPixel(x, y, win.pen.color().rgba())
if e <= w:
if change:
y += sy
else:
x += sx
e += h
else:
x += sx
y += sy
e -= w
i += 1