Created
April 4, 2019 03:42
-
-
Save jqly/9aa14856d4383da719093b27ea77426a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void line(int x0, int y0, int x1, int y1) { | |
int dx = abs(x1-x0), sx = x0<x1 ? 1 : -1; | |
int dy = abs(y1-y0), sy = y0<y1 ? 1 : -1; | |
int err = (dx>dy ? dx : -dy)/2, e2; | |
for(;;){ | |
setPixel(x0,y0); | |
if (x0==x1 && y0==y1) break; | |
e2 = err; | |
if (e2 >-dx) { err -= dy; x0 += sx; } | |
if (e2 < dy) { err += dx; y0 += sy; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment