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    

Thursday, February 4, 2010

Computer Graphics:midpoint circle drawing algorithm

//---------------------------------------------------------------------------
#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::Button1Click(TObject *Sender)
{
        int pk;
        int xc,yc,x,y,r;
        xc=StrToInt(Edit1->Text);
        yc=StrToInt(Edit2->Text);
        r=StrToInt(Edit3->Text);
        pk=1-r;
 x=0;
 y=r;
 do{
 if(pk<0)
 {
  x++;
  pk=pk+2*x+3;
 }
 else
 {
  x++;
  y--;
  pk=pk+2*x-2*y+5;
 }
                Form1->Canvas->Pixels[xc+x][yc+y]=RGB(250,0,0);
                Form1->Canvas->Pixels[xc+x][yc-y]=RGB(0,250,0);
                Form1->Canvas->Pixels[xc-x][yc+y]=RGB(0,0,250);
                Form1->Canvas->Pixels[xc-x][yc-y]=RGB(250,0,0);
                Form1->Canvas->Pixels[xc+y][yc+x]=RGB(0,250,0);
                Form1->Canvas->Pixels[xc+y][yc-x]=RGB(0,0,250);
                Form1->Canvas->Pixels[xc-y][yc+x]=RGB(250,0,0);
                Form1->Canvas->Pixels[xc-y][yc-x]=RGB(0,250,0);
 }while(x<=y);



}
//---------------------------------------------------------------------------

No comments:

Post a Comment

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