Make your own free website on Tripod.com
using System;
using System.Drawing;
using System.Windows.Forms;

class Pintar:Form
{
int rx=150,ry=70,xcenter=150,ycenter=100,radio=50;
double dtheta,ct,st,xr,yr,xtemp;
double d;
int p,px,py,x,y,ry2,rx2,tworx2,twory2;
public static void Main()
{
Application.Run(new Pintar());
}
public Pintar()
{
Text="PrAcTiCa 1 LiNeaS";
BackColor=SystemColors.Window;
ForeColor=SystemColors.WindowText;
ResizeRedraw=true;
}

protected void pinta(PaintEventArgs objeto)
{
Graphics gr=objeto.Graphics;
Pen pen0=new Pen(ForeColor);



//algoritmo elipse punto medio
gr.DrawLine(pen0,xcenter+x,ycenter+y,xcenter,ycenter);
gr.DrawLine(pen0,xcenter-x,ycenter+y,xcenter,ycenter);
gr.DrawLine(pen0,xcenter+x,ycenter-y,xcenter,ycenter);
gr.DrawLine(pen0,xcenter-x,ycenter-y,xcenter,ycenter);

}
protected override void OnPaint(PaintEventArgs objeto)
{

Graphics grfx=objeto.Graphics;
Pen pen=new Pen(ForeColor);

//algoritmo para generacion de elipse
ry2=ry*ry;
rx2=rx*rx;
twory2=2*ry2;
tworx2=2*rx2;
//codigo para region 1
x=0;
y=ry;
pinta(objeto);
p=System.Convert.ToInt32(Math.Round(ry2-rx2*ry+(0.25*rx2)));
px=0;
py=tworx2*y;
while(px<py)
{
x=x+1;
px=px+twory2;
if(p>=0)
{
y=y-1;
py=py-tworx2;
}
if(p<0)

p=p+ry2+px;

else
p=p+ry2+px-py;
pinta(objeto);
}
//codigo para la region 2
p=System.Convert.ToInt32(Math.Round(ry2*(x+0.5)*(x+0.5)+rx2*(y-1)*(y-1)-rx2*ry2));
while(y>0)
{
y=y-1;
py=py-tworx2;
if(p<=0)
{
x=x+1;
px=px-twory2;
}
if(p>0)
p=p+rx2-py;
else
p=p+rx2-py+px;
pinta(objeto);
}



}
}

Aqui en los dos ciclos WHILE se hace el rellenado de la elipse y es ahi donde se pinta el obejto y se obtiene que la figura eliptica que rellena.