void smooth Point Point int int dx dy int s1 sign dx s2 sign dy double

 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
void smooth(Point a, Point b) {
int x = a.x, y = a.y;
int dx = b.x - a.x, dy = b.y - a.y;
int s1 = sign(dx), s2 = sign(dy);
double tga = (double)dy/dx;
bool intense = (0 <= tga && tga <= 1) || tga <= -1;
dx = abs(dx);
dy = abs(dy);
bool swaped = false;
if (dy > dx) {
std::swap(dx, dy);
swaped = true;
}
int I = 255;
int e = I*dx;
int m = 2*dy*I;
int w = 2*e;
buff.plot(x, y, (unsigned char)(intense ? m/(4*dx) : 1 - m/(4*dx)));
for (int i = 0; i <= dx; i++) {
if (e >= w - m) {
x += swaped ? s1 : (y += s2, 0);
e -= w;
}
x += swaped ? (y += s2, 0) : s1;
e += m;
buff.plot(x, y, (unsigned char)(intense ? e/(2*dx) : 1 - e/(2*dx)));
}
}