Draw a line from x1,y1 to x2,y2 using the Bresenham algorithm. */
| 124 | |
| 125 | /* Draw a line from x1,y1 to x2,y2 using the Bresenham algorithm. */ |
| 126 | void lwDrawLine(lwCanvas *canvas, int x1, int y1, int x2, int y2, int color) { |
| 127 | int dx = abs(x2-x1); |
| 128 | int dy = abs(y2-y1); |
| 129 | int sx = (x1 < x2) ? 1 : -1; |
| 130 | int sy = (y1 < y2) ? 1 : -1; |
| 131 | int err = dx-dy, e2; |
| 132 | |
| 133 | while(1) { |
| 134 | lwDrawPixel(canvas,x1,y1,color); |
| 135 | if (x1 == x2 && y1 == y2) break; |
| 136 | e2 = err*2; |
| 137 | if (e2 > -dy) { |
| 138 | err -= dy; |
| 139 | x1 += sx; |
| 140 | } |
| 141 | if (e2 < dx) { |
| 142 | err += dx; |
| 143 | y1 += sy; |
| 144 | } |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | /* Draw a square centered at the specified x,y coordinates, with the specified |
| 149 | * rotation angle and size. In order to write a rotated square, we use the |
no test coverage detected