Page 71 - DCAP313_LAB_ON_COMPUTER_GRAPHICS
P. 71

Unit 5: Implementing Ellipse Algorithm



                     p=(ry 1 –rx 1 *ry+(0.25*rx 1 ));                                             Notes
                     px=0;
                     py=rx 2 *y;
                     while(px<py)
                     {
                     x=x+1;
                     px=px+ry 2 ;
                     if(p>=0)
                     y=y–1;
                     py=py–rx 2 ;
                     if(p<0)
                     p=p+ry1+px;
                     else
                     p=p+ry 1 +px–py;
                     plotpoints(xcenter,ycenter,x,y);
                     /* REGION 2*/
                     p=(ry 1 *(x+0.5)*(x+0.5)+rx1*(y–1)*(y–1)–rx 1 *ry 1 );
                     while(y>0)
                     {
                     y=y–1;
                      py=py–rx 2 ;
                     if(p<=0)
                     {
                     x=x+1;
                     px=px+ry 2 ;
                     }
                     if(p>0)
                     p=p+rx 1 –py;
                     else
                     p=p+rx 1 –py+px;
                     plotpoints(xcenter,ycenter,x,y);
                     }
                     }
                     getch();
                     return(0);
                     }
                     int plotpoints(int xcenter,int ycenter,int x,int y)
                     {
                     putpixel(xcenter+x,ycenter+y,6);
                     putpixel(xcenter–x,ycenter+y,6);
                     putpixel(xcenter+x,ycenter–y,6);
                     putpixel(xcenter–x,ycenter–y,6);
                     }
                                             LOVELY PROFESSIONAL UNIVERSITY                                    65
   66   67   68   69   70   71   72   73   74   75   76