[A89] filling ellipses


[Prev][Next][Index][Thread]

[A89] filling ellipses




Using the algebraic formula, I came up with a function to fill an ellipse.  Unfortunately, it's
fairly slow (it scans until it hits the edge, draws a line across, then scans again on the next
row).  I went ahead and used clipped drawing functions.  If anyone has any ideas for making it
faster, that would be great.
jeff

void DrawEllipse (double h, double k, double a, double b, short Attr)	//note: in this case, a
always corresponds to x
{	//rectangle around ellipse: (h-a,k-b) (h+a,k-b) (h+a,k+b) (h-a,k+b)
	char flag;
	double x,y,value;
	SetCurClip (&(SCR_RECT){{0, 0, 159, 99}});
	SetCurAttr (Attr);
	for(y=k-b; y<k; y++)
	{
		flag='n';
		for(x=h-a; x<h; x++)
		{
			value = (x-h)*(x-h) / (a*a) + (y-k)*(y-k) / (b*b);
			//printf_xy(1,1,"%g",value);
			if( value <= 1)
			{
				MoveTo(x,y);
				LineTo(2*h-x,y);
				MoveTo(x,2*k-y);
				LineTo(2*h-x,2*k-y);
				flag='y';
				/*DrawPix (x, y, A_XOR);
				DrawPix (2*h-x, y, A_XOR);
				DrawPix (x, 2*k-y, A_XOR);
				DrawPix (2*h-x, 2*k-y, A_XOR);*/
			}
			if(flag=='y')
			break;
		}
		//ngetchx();
	}
	DrawLine(h-a,k,h+a,k,Attr);
	DrawClipPix(h,k+b);
	DrawClipPix(h,k-b);
}

void _main(void)
{
	ClrScr();
	DrawEllipse(LCD_WIDTH/2, LCD_HEIGHT/2, LCD_WIDTH/2, LCD_HEIGHT/2, A_XOR);
	ngetchx();
}

__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/