Showing posts with label bresenham's circle drawing algorithm. Show all posts
Showing posts with label bresenham's circle drawing algorithm. Show all posts

Tuesday, 23 February 2016

Bresenham's circle drawing


Q)Circle generation using bresenham’s circle drawing algorithm.
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <math.h>
#include<iostream.h>
void drawcir(float x,float y,float p,float q){
putpixel(x+p,y+q,3);
putpixel(x-p,y+q,3);
putpixel(x+p,y-q,3);
putpixel(x-p,y-q,3);
putpixel(x+q,y+p,3);
putpixel(x-q,y+p,3);
putpixel(x+q,y-p,3);
putpixel(x-q,y-p,3);
    }
int main()
{
   int gdriver = DETECT, gmode;
   initgraph(&gdriver, &gmode, "C:\\TC\\bgi");
   float gx,gy,grad;
   cout<<"enter the x coordinateof the centre";
   cin>>gx;
   cout<<"enter the y coor of the centre";
   cin>>gy;
  cout<<"enter the radious of the circle";
  cin>>grad;
  float p=0;
  float q=grad;
  float d=3-2*grad;
  while(p<q){
  drawcir(gx,gy,p,q);
p++;
if(d<0)
{d=d+4*p+6;
}
  else{
q--;
  d=d+4*(p-q)+10;
  }
drawcir(gx,gy,p,q);
  }
   getch();
   closegraph();
   return 0;
}