Home      Affiliated Colleges      Course content      First Sem     Second Sem     Third Sem     Fourth Sem     Fifth Sem     Sixth Sem     Seventh Sem     Eighth Sem     Lab report 4th sem     Contact    

Wednesday, February 3, 2010

Computer Graphics-coding for ellipse


//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button5Click(TObject *Sender)
{
  int xc,yc,rx,ry,x,y,a,b;
 float pk;
        rx=StrToInt(Edit3->Text);
        ry=StrToInt(Edit4->Text);
        xc=StrToInt(Edit1->Text);
        yc=StrToInt(Edit2->Text);
        //For region 1
 pk=ry*ry-rx*rx*ry+((rx*rx)/4);
 x=0;
 y=ry;
        a=0;
        b=2*rx*rx*y;
 do{
  Form1->Canvas->Pixels[xc+x][yc+y]=RGB(255,0,0);
                Form1->Canvas->Pixels[xc+x][yc-y]=RGB(255,0,0);
                Form1->Canvas->Pixels[xc-x][yc+y]=RGB(255,0,0);
                Form1->Canvas->Pixels[xc-x][yc-y]=RGB(255,0,0);
                 a=a+2*ry*ry;
  if(pk<0)
  {
   pk=pk+a+ry*ry;
   x=x+1;
  }
  else
  {
   pk=pk+a-b+ry*ry;
                        b=b-2*rx*rx;
   x=x+1;
   y=y-1;
  }
 }
 while((2*ry*ry*x)<=(2*rx*rx*y));
 //For region 2

 pk=ry*ry*(x+0.5)*(x+0.5)+rx*rx*(y-1)*(y-1)-rx*rx*ry*ry;
 do{
  Form1->Canvas->Pixels[xc+x][yc+y]=RGB(255,0,0);
                Form1->Canvas->Pixels[xc+x][yc-y]=RGB(255,0,0);
                Form1->Canvas->Pixels[xc-x][yc+y]=RGB(255,0,0);
                Form1->Canvas->Pixels[xc-x][yc-y]=RGB(255,0,0);
                b=b-2*rx*rx;
  if(pk>0)
  {
   pk=pk-b+rx*rx;
   y=y-1;
  }
  else
  {
   pk=pk+a-b+rx*rx;
                        a=a+2*ry*ry;
   x=x+1;
   y=y-1;
  }
 }
 while(y>=0);
}      
//---------------------------------------------------------------------------

No comments:

Post a Comment

^ Scroll to Top Related Posts with Thumbnails ^ Go to Top