Ellipse Drawing Algorithm in Computer Graphics

#include<graphics.h>
#include<stdio.h>
#include<conio.h>
#include<math.h>

void drawellipse(int, int, int, int);

void main()
{
  int gd=DETECT,gm;
  initgraph(&gd,&gm,"c:\\tc\\bgi");
  
  int xc,yc,rx,ry;
  xc=getmaxx()/2;
  yc=getmaxy()/2;
  rx=100;
  ry=80;
  drawellipse(xc,yc,rx,ry);
  getch();
  closegraph();
}

void drawellipse(int xc,int yc,int rx,int ry)
{
  int x,y;
  float theta;
  const float PI=3.14;
  for(theta=0.0;theta<=360;theta++)
  {
    x= xc+rx*cos(theta*PI/180.0);
    y= yc+ry*sin(theta*PI/180.0);
    putpixel(x,y,1);
    delay(10);
  }
}

OUTPUT:


No comments:

Post a Comment