Can anybody tell me how to draw a circle without floating point numbers?
Can anybody tell me how to draw a circle without floating point numbers?
Code:#include <stdio.h> int main(void) { puts(" XX"); puts("X X"); puts(" XX"); return 0; } itsme@itsme:~/C$ ./circle XX X X XX
If you understand what you're doing, you're not learning anything.
Radius can change dynamically.. -
Told that, It may not be perfect circle. But given a radius, how do you draw circle?
Looking at a circle from a 90 degree angle...Code:#include <stdio.h> int main(void) { int radius = 10; /* value 1 through screen_width/2 */ int i; for(i = 0;i < radius*2;++i) putchar('X'); putchar('\n'); return 0; }
If you understand what you're doing, you're not learning anything.
PHP Code:
#include <stdio.h>
int main (void)
{
int radius = 10;
int x, y;
for (y = -radius; y <= radius; y++)
{
for (x = -radius; x <= radius; x++)
{
if (x * x + y * y <= radius * radius)
putchar ('X');
else
putchar (' ');
}
putchar ('\n');
}
return 0;
}
hello, internet!
I think, this looks better. Thanks Moi
Code:#include <stdio.h> int main (void) { int radius = 10; int x, y; for (y = -radius; y <= radius; y++) { for (x = -radius; x <= radius; x++) { if ( (x * x + y * y <= ( (radius * radius)+1) ) && ( x * x + y * y >= (radius * radius) -1 )) putchar ('X'); else putchar (' '); } putchar ('\n'); } return 0; }
PHP Code:
XXX
X X
X X
X X
X X
X X
X X
X X
XXX
I wrote an OpenGL clock demo that uses Bressenhams line and circle algorithms. You can find it here:
http://cboard.cprogramming.com/showthread.php?t=51487