Draw circle

This is a discussion on Draw circle within the C Programming forums, part of the General Programming Boards category; Can anybody tell me how to draw a circle without floating point numbers?...

  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,163
    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,163
    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
    moi
    moi is offline
    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:

    Line/Circle algos (clock demo)

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, 05: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, 03:39 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21