Skip to content

Instantly share code, notes, and snippets.

@myndzi
Created December 3, 2013 01:32
Show Gist options
  • Save myndzi/7762383 to your computer and use it in GitHub Desktop.
Save myndzi/7762383 to your computer and use it in GitHub Desktop.
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