best way to draw a circle using curses
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > best way to draw a circle using curses




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    best way to draw a circle using curses  
DaVinci


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-13-06 12:51 PM

hi,all...
here are my codes on how to a draw a circle using curses,but I found
it's not a good way and there are some bugs.
#include<vector>
#include<curses.h>
using std::vector;
struct Point
{
Point(int i_,int j_)
{
i = i_;
j = j_;
}
int i;
int j;
};



vector<Point>  draw_circle(const Point& center,int radius)
{
vector<Point> vp;
for(int i = 0; i<LINES;i++)
for(int j = 0;j<COLS;j++)
{
if((i - center.i)*(i - center.i) + (j - center.j)*(j - center.j) ==
radius*radius )
{
vp.push_back(Point(i,j));
move(i,j);
addstr("a");
refresh();
usleep(100000);
}
}
return vp;
}


int main()
{
Point center (22,22);
int radius = 2;  //int radius = 1,.....take care of here..@@
initscr();
clear();
draw_circle(center,radius);
sleep(33);
endwin();
return 0;
}

Q1:
at main() function,
I found it is so strange that if I declare int radius = 2,or int radius
= 1,or some
others ,the picture I draw is only have four point,but if the radius is
bigger,there may be more,but the quantity is not respected.

Q2:are there a better way to draw a circle??
Thanks in advance.






[ Post a follow-up to this message ]



    Re: best way to draw a circle using curses  
Fred Kleinschmidt


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-13-06 10:54 PM


"DaVinci" <apple.davinci@gmail.com> wrote in message
news:1142257365.474676.286410@j33g2000cwa.googlegroups.com...
> hi,all...
> here are my codes on how to a draw a circle using curses,but I found
> it's not a good way and there are some bugs.
> #include<vector>
> #include<curses.h>
> using std::vector;
> struct Point
> {
> Point(int i_,int j_)
> {
> i = i_;
> j = j_;
> }
> int i;
> int j;
> };
>
>
>
> vector<Point>  draw_circle(const Point& center,int radius)
> {
> vector<Point> vp;
> for(int i = 0; i<LINES;i++)
> for(int j = 0;j<COLS;j++)
> {
> if((i - center.i)*(i - center.i) + (j - center.j)*(j - center.j) ==
> radius*radius )
> {
> vp.push_back(Point(i,j));
> move(i,j);
> addstr("a");
> refresh();
> usleep(100000);
> }
> }
> return vp;
> }
>
>
> int main()
> {
> Point center (22,22);
> int radius = 2;  //int radius = 1,.....take care of here..@@
> initscr();
> clear();
> draw_circle(center,radius);
> sleep(33);
> endwin();
> return 0;
> }
>
> Q1:
> at main() function,
> I found it is so strange that if I declare int radius = 2,or int radius
> = 1,or some
> others ,the picture I draw is only have four point,but if the radius is
> bigger,there may be more,but the quantity is not respected.
>
> Q2:are there a better way to draw a circle??
> Thanks in advance.
>

Think about it for a minute.
How many combinations of INTEGERS i, j, and r are there,
for any given r, such that i**2 + j**2 = r**2?

--
Fred L. Kleinschmidt
Boeing Associate Technical Fellow
Technical Architect, Software Reuse Project







[ Post a follow-up to this message ]



    Re: best way to draw a circle using curses  
Fletcher Glenn


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-13-06 10:54 PM

DaVinci wrote:
> hi,all...
> here are my codes on how to a draw a circle using curses,but I found
> it's not a good way and there are some bugs.
> #include<vector>
> #include<curses.h>
> using std::vector;
> struct Point
> {
> 	Point(int i_,int j_)
> 	{
> 		i = i_;
> 		j = j_;
> 	}
> 	int i;
> 	int j;
> };
>
>
>
> vector<Point>  draw_circle(const Point& center,int radius)
> {
> 	vector<Point> vp;
> 	for(int i = 0; i<LINES;i++)
> 		for(int j = 0;j<COLS;j++)
> 		{
> 			if((i - center.i)*(i - center.i) + (j - center.j)*(j - center.j) ==
> radius*radius )
> 			{
> 				vp.push_back(Point(i,j));
> 				move(i,j);
> 				addstr("a");
> 				refresh();
> 				usleep(100000);
> 			}
> 		}
> 	return vp;
> }
>
>
> int main()
> {
> 	Point center (22,22);
> 	int radius = 2;  //int radius = 1,.....take care of here..@@
> 	initscr();
> 	clear();
> 	draw_circle(center,radius);
> 	sleep(33);
> 	endwin();
> 	return 0;
> }
>
> Q1:
> at main() function,
> I found it is so strange that if I declare int radius = 2,or int radius
> = 1,or some
> others ,the picture I draw is only have four point,but if the radius is
> bigger,there may be more,but the quantity is not respected.
>
> Q2:are there a better way to draw a circle??
> Thanks in advance.
>

Try a net search on "Breshenham Circle Algorithm".

--

Fletcher Glenn






[ Post a follow-up to this message ]



    Re: best way to draw a circle using curses  
DaVinci


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-14-06 12:49 PM


Fred Kleinschmidt wrote:
> "DaVinci" <apple.davinci@gmail.com> wrote in message
> news:1142257365.474676.286410@j33g2000cwa.googlegroups.com... 
>
> Think about it for a minute.
> How many combinations of INTEGERS i, j, and r are there,
> for any given r, such that i**2 + j**2 = r**2?
If I change INTEGES to double,the result may be better.
But move(int,int) required arguments of int types.

There is no  move(double,double).

so the circle  must be ugly. ??
>
> --
> Fred L. Kleinschmidt
> Boeing Associate Technical Fellow
> Technical Architect, Software Reuse Project






[ Post a follow-up to this message ]



    Re: best way to draw a circle using curses  
RickE


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-14-06 12:49 PM

A little set of Bresenham drawing routines can be found here;

http://www.pinenet.com/eng/Draw.html

It was an example of drawing to the linux framebuffer console using
FreePascal. I'm not sure you can draw circles in [n]curses text mode.

For the truly ambitious, the old Bellcore MGR window manager has
bitmapping routines as well as text. I can't compile it, but I think
there is a lot of salvagable material.






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 04:40 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register