Skip to content

Instantly share code, notes, and snippets.

@denkspuren
Last active August 29, 2015 14:07
Show Gist options
  • Save denkspuren/df24bf57ae3a44310631 to your computer and use it in GitHub Desktop.
Save denkspuren/df24bf57ae3a44310631 to your computer and use it in GitHub Desktop.
Draw Circle according to Horn's Method
// https://de.wikipedia.org/wiki/Rasterung_von_Kreisen#Methode_von_Horn
void drawCircle(int xPos, int yPos, int r) {
int d = -r;
int x = r;
int y = 0;
while (y <= x) {
point(xPos+x,yPos+y); // might be executed in parallel
point(xPos-x,yPos+y);
point(xPos+x,yPos-y);
point(xPos-x,yPos-y);
point(yPos+y,xPos+x);
point(yPos-y,xPos+x);
point(yPos+y,xPos-x);
point(yPos-y,xPos-x);
d += 2*y + 1; // d += (y << 1) + 1;
y++;
if (d > 0 ) {
d -= 2*x + 2; // d -= (x << 1) + 2;
x--;
}
}
}
void setup() {
size(400,400);
point(200,200);
for (int r=5; r<=200; r+=10)
drawCircle(200,200,r);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment