Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Program to implement Bresenhams line generation algorithm */
- #include <graphics.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <conio.h>
- #include <dos.h>
- // method that plots the circle points in all the 8 quadrants
- void drawcircle(int xc, int yc, int x,int y)
- {
- putpixel(xc+x,yc+y,5); //quad 1
- putpixel(xc+y,yc+x,6); //quad 2
- putpixel(xc-x,yc+y,5); //quad 3
- putpixel(xc-y,yc+x,6); //quad 4
- putpixel(xc-x,yc-y,5); //quad 5
- putpixel(xc-y,yc-x,6); //quad 6
- putpixel(xc+x,yc-y,5); //quad 7
- putpixel(xc+y,yc-x,6); //quad 8
- }
- // function that calculates the points of the circle to be plotted
- // inputs are the the center co-ordinates and value of the radius
- void midPointCircle(int xc, int yc, int radius){
- // x, y are used to store the new points of the circle
- // parameter decides whether a point is inside , outside or on the circle
- int x, y, parameter;
- // initial values for x, y, parameter
- x=0;
- y=radius;
- parameter = 1-radius;
- // plot the initial point
- drawcircle(xc,yc,x,y);
- while(x<y)
- {
- // parameter is less than 0 hence point is inside the circle so we increase the value of x
- if(parameter<0)
- {
- parameter=parameter+2*x+3;
- x++;
- }
- // parameter is 0 or greater than 0
- // so we increase both values of x and y
- else{
- parameter=parameter+2*(x-y)+5;
- x++;
- y--;
- }
- drawcircle(xc,yc,x,y);
- delay(10);
- }
- }
- void main()
- {
- int gd=0,gm, i = 50;
- initgraph(&gd,&gm,"C:\\TC\\BGI");
- // circle with center (320, 240) and radius = 150
- midPointCircle(320, 240, 150);
- while(i < 100){
- midPointCircle(320, 240, i);
- i += 5;
- }
- getch();
- }
Add Comment
Please, Sign In to add comment