Thread: Draw circle

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    175

    Draw circle

    Can anybody tell me how to draw a circle without floating point numbers?

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    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.

  3. #3
    Registered User
    Join Date
    Feb 2003
    Posts
    175
    Radius can change dynamically.. -

  4. #4
    Registered User
    Join Date
    Feb 2003
    Posts
    175
    Told that, It may not be perfect circle. But given a radius, how do you draw circle?

  5. #5
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    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;
    }
    Looking at a circle from a 90 degree angle...
    If you understand what you're doing, you're not learning anything.

  6. #6
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    PHP Code:
    #include <stdio.h>

    int main (void)
    {
      
    int radius 10;
      
    int xy;

      for (
    = -radius<= radiusy++)
      {
        for (
    = -radius<= radiusx++)
        {
          if (
    <= radius radius)
            
    putchar ('X');
          else
            
    putchar (' ');
        }
        
    putchar ('\n');
      }
      return 
    0;

    hello, internet!

  7. #7
    Registered User
    Join Date
    Feb 2003
    Posts
    175
    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 

  8. #8
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Draw The Circle
    By rifatgunduz in forum C++ Programming
    Replies: 11
    Last Post: 01-26-2005, 06:49 AM
  2. Draw a circle?
    By TheShaggmeister in forum C++ Programming
    Replies: 6
    Last Post: 07-22-2003, 01:35 PM
  3. Best way to draw circle!!??
    By OneStiffRod in forum Game Programming
    Replies: 12
    Last Post: 04-28-2003, 07:57 AM
  4. circle filling
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 06-08-2002, 05:37 AM
  5. point lies in circle?
    By cozman in forum Game Programming
    Replies: 3
    Last Post: 12-20-2001, 04:39 PM