Created
December 3, 2013 01:32
-
-
Save myndzi/7762383 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
function circle(buffer, cx, cy, radius) { | |
var error = -radius, | |
x = radius, | |
y = 0, | |
lastY; | |
while (x >= y) { | |
lastY = y; | |
error += y; | |
++y; | |
error += y; | |
plot4points(buffer, cx, cy, x, lastY); | |
if (error >= 0) { | |
if (x != lastY) | |
plot4points(buffer, cx, cy, lastY, x); | |
error -= x; | |
--x; | |
error -= x; | |
} | |
} | |
} | |
function plot4points(buffer, cx, cy, x, y) { | |
horizontalLine(buffer, cx - x, cy + y, cx + x); | |
if (x != 0 && y != 0) | |
horizontalLine(buffer, cx - x, cy - y, cx + x); | |
} | |
function horizontalLine(buffer, fromX, y, toX) { | |
for (var i = fromX; i < toX; i++) { | |
buffer[y][i]++; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment