document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. /* Program to implement Bresenhams line generation algorithm */
  2.  
  3. #include <graphics.h>
  4. #include <stdlib.h>
  5. #include <stdio.h>
  6. #include <conio.h>
  7. #include <dos.h>
  8.  
  9. // method that plots the circle points in all the 8 quadrants
  10. void drawcircle(int xc, int yc, int x,int y)
  11. {
  12.     putpixel(xc+x,yc+y,5);       //quad 1
  13.     putpixel(xc+y,yc+x,6);       //quad 2
  14.     putpixel(xc-x,yc+y,5);       //quad 3
  15.     putpixel(xc-y,yc+x,6);       //quad 4
  16.     putpixel(xc-x,yc-y,5);       //quad 5
  17.     putpixel(xc-y,yc-x,6);       //quad 6
  18.     putpixel(xc+x,yc-y,5);       //quad 7
  19.     putpixel(xc+y,yc-x,6);       //quad 8
  20. }
  21.  
  22. // function that calculates the points of the circle to be plotted
  23. // inputs are the the center co-ordinates and value of the radius
  24. void midPointCircle(int xc, int yc, int radius){
  25.    
  26.     // x, y are used to store the new points of the circle
  27.     // parameter decides whether a point is inside , outside or on the circle
  28.     int x, y, parameter;
  29.  
  30.     // initial values for x, y, parameter
  31.     x=0;
  32.     y=radius;  
  33.     parameter = 1-radius;
  34.    
  35.     // plot the initial point
  36.     drawcircle(xc,yc,x,y);
  37.    
  38.     while(x<y)
  39.     {
  40.         // parameter is less than 0 hence point is inside the circle so we increase the value of x
  41.         if(parameter<0)
  42.         {
  43.             parameter=parameter+2*x+3;
  44.             x++;
  45.         }
  46.        
  47.         // parameter is 0 or greater than 0
  48.         // so we increase both values of x and y
  49.         else{
  50.             parameter=parameter+2*(x-y)+5;
  51.             x++;
  52.             y--;
  53.  
  54.         }
  55.        
  56.         drawcircle(xc,yc,x,y);
  57.         delay(10);
  58.    
  59.     }
  60. }
  61.  
  62. void main()
  63. {
  64.     int gd=0,gm, i = 50;
  65.    
  66.     initgraph(&gd,&gm,"C:\\\\TC\\\\BGI");
  67.    
  68.     // circle with center (320, 240) and radius = 150
  69.     midPointCircle(320, 240, 150);
  70.    
  71.     while(i < 100){
  72.         midPointCircle(320, 240, i);
  73.         i += 5;
  74.     }
  75.     getch();
  76. }
');