Page 65 - DCAP313_LAB_ON_COMPUTER_GRAPHICS
P. 65

Unit 4: Implementing Circle Algorithm



               5.  If D is outside the circle, choose (xn+1, yn–1) as the next pixel.             Notes
                 (a)  True                       (b)  False

            4.3 Bresenham’s Circle Drawing Algorithm


            The following steps of Bresenham’s Circle Drawing Algorithm:
               1.  Start
               2.  Initialize the graphics mode

               3.  Read the radius of the circle
               4.  Initialize the graphics mode
               5.  Initialize starting points x=0,y=r
               6.  Initialize decision variable d=3 – 2 * r

               7.  Plot (x,y)
                 a. plot eight points (+x,+y),(+x,–y),(–x,+y),(–x,–y),(+y,+x) ,(+y,–x),

                 (–y,+x),(–y,–x)
               8.  If d< =0, d = d + 4 * x + 6 else {d = d + 4 (x–y) + 10, y = y–1}
               9.  x=x +1
              10.  Insert delay to observe the drawing process

              11.  Repeat 6- 10 until x<y
            4.3.1 Bresenham’s Circle Drawing Algorithm Using C Programming
                          #include<stdio.h>
                          #include<conio.h>
                          #include<graphics.h>
                          void main()
                          {
                             int gd=DETECT, gm;
                             int x,y,r;
                             void cir(int, int, int);
                             printf(“Enter the Mid points and Radious:”);
                             scanf(“%d%d%d”, &x, &y, &r);
                             initgraph(&gd, &gm, “”);
                             cir(x, y, r);
                             getch();
                             closegraph();
                          }
                          void cir(int x 1 , int y 1 , int r)
                          {
                             int x=0,y=r,p=1–r;
                             void cliplot(int, int, int, int);
                             cliplot(x 1 , y 1 , x, y);
                             while(x<y)


                                             LOVELY PROFESSIONAL UNIVERSITY                                    59
   60   61   62   63   64   65   66   67   68   69   70