Can We Draw a Circle using ASCII?

Hi All!
Can We draw a Circle by using ASCII Codes?

 
  Need Help
Abdullah Samo wrote:
Can We draw a Circle by using ASCII Codes?

Like so?
1
2
3
4
5
#include <iostream>
int main()
{
   std::cout << 'o';
}



Well, maybe:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;

int main()
{
   const int    N      = 30;
   const int    SIZE   = 21;
   const char   SYMBOL = '*';
   const double PI     = 4 * atan( 1.0 );

   double dtheta = 2.0 * PI / N;
   vector<string> grid( SIZE, string( SIZE, ' ' ) );

   for ( int t = 0; t < N; t++ )
   {
      double theta = t * dtheta;
      int i = 0.5 * ( 1 + cos( theta ) ) * ( SIZE - 1 ) + 0.5;
      int j = 0.5 * ( 1 + sin( theta ) ) * ( SIZE - 1 ) + 0.5;
      grid[i][j] = SYMBOL;
   }

   for ( string s : grid ) cout << s << '\n';
}




Actually, I quite like this hexadecimal clock:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;

int main()
{
   const int    N      = 12;
   const int    SIZE   = 21;
   const char * SYMBOL = "123456789ABC";
   const double PI     = 4 * atan( 1.0 );

   double dtheta = 2.0 * PI / N;
   vector<string> grid( SIZE, string( SIZE, ' ' ) );

   for ( int t = 0; t < N; t++ )
   {
      double theta = PI - ( t + 1 ) * dtheta;
      int i = 0.5 * ( 1 + cos( theta ) ) * ( SIZE - 1 ) + 0.5;
      int j = 0.5 * ( 1 + sin( theta ) ) * ( SIZE - 1 ) + 0.5;
      grid[i][j] = SYMBOL[t];
   }

   for ( string s : grid ) cout << s << '\n';
}


          C          
     B         1     
                     
                     
                     
 A                 2 
                     
                     
                     
                     
9                   3
                     
                     
                     
                     
 8                 4 
                     
                     
                     
     7         5     
          6          
Last edited on
there are famous pictures redone in ascii: my professor in college had the famous star wars original movie poster in ascii as a wall poster. So yes, you can.
it will be a bit of a challenge, because letters are NOT square in most consoles. You can SET the console font to BE square in some systems, and that would help make it pretty, or you can adjust your code to deal with the problem (so, you would draw an oval, using the conic section equation of an oval probably) and the way the oval is rendered would make it back to a circle. (think of it as drawing on a sheet of rubber that is stretched in the x direction and then the tension is removed).

Topic archived. No new replies allowed.