Skip to content

Instantly share code, notes, and snippets.

@BlackHC
Last active December 15, 2015 16:39
Show Gist options
  • Select an option

  • Save BlackHC/5290996 to your computer and use it in GitHub Desktop.

Select an option

Save BlackHC/5290996 to your computer and use it in GitHub Desktop.
void drawEighthOfCircle( int radius ) {
int y = radius;
int x = 0;
// invariant: radius^2 <= x^2 + y^2 < (radius+1)^2
int maxLength = (radius+1)*(radius+1);
while( x <= y ) {
setPixel( x, y );
x++;
if( x*x + y*y >= maxLength ) {
y--;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment