Draw A Ring In Computer Graphics Using Midpoint Circle Drawing Algorithm


 Draw A Ring In C Graphics


draw a ring in computer graphics,draw a ring in c graphics,draw a ring in computer graphics using midpoint circle drawing algorithm,draw a ring in c graphics using midpoint circle drawing algorithm

#include<graphics.h>

#include<conio.h>

#define r1(a) (a+0.5)

#include<string.h>

#include<math.h>


int gdrivers=DETECT,gmode;

void mid_point(int xc, int yc, int r);

void dda( int xa, int ya, int xb, int yb);

void dda();


void main()

{

   int x, y;

   clrscr();


   initgraph(&gdrivers, &gmode, "c:\\turboc3\\bgi");

   setbkcolor(BLACK);


   dda(300, 230, 385, 170);

   dda(300, 230, 215, 170);

   dda(215, 170, 385, 170);

   dda(300, 230, 268, 170);

   dda(300, 230, 333, 170);

   dda(250, 146, 268, 170);

   dda(300, 136, 268, 170);

   dda(300, 136, 333, 170);

   dda(350, 146, 333, 170);



   mid_point(300, 250, 70);

   mid_point(300, 250, 90);

   mid(300, 250, 115);



   getch();

}


void dda(int xa, int ya, int xb, int yb)

{

    float xincr, yincr, x, y;

    int k, steps, dx, dy;

    dx = (xb-xa);

    dy = (yb-ya);

    if(abs(dx) > abs(dy))

       steps=abs(dx);

    else

       steps=abs(dy);

    xincr=dx/(float)steps;

    yincr=dy/(float)steps;

    x=xa;

    y=ya;

    putpixel(r1(x), r1(y), 1);

    for(k=0;k<steps;k++)

    {

      x+=xincr;

      y+=yincr;

      putpixel(r1(x), r1(y), 1);

    }


}

void mid_point(int xc, int yc, int r)

{


 int x=0, y=r, d=1-r;

 draw_circle(xc, yc, x, y);

 while(x<y)

 {

  x++;

  if(d<0)

  {

   d=d+2*x+1;

  }

  else

  {

   y--;

   d=d+2*(x-y)+1;

  }

  draw_circle(xc, yc, x, y);

 }

}


int draw_circle(int x0, int y0, int x, int y)

{

 //setbkcolor();

 putpixel(x0+x, y0+y, BLUE);

 putpixel(x0+y, y0+x, BLUE);

 putpixel(x0-y, y0+x, BLUE);

 putpixel(x0-x, y0+y, BLUE);

// putpixel(x0-x, y0-y, BLUE);

 putpixel(x0-y, y0-x, BLUE);

 putpixel(x0+y, y0-x, BLUE);

// putpixel(x0+x, y0-y, BLUE);

 return 0;

}

int mid(int xc, int yc, int r)

{


 int x=0, y=r, d=1-r;

 draw_circle(xc, yc, x, y);

 while(x<y)

 {

  x++;

  if(d<0)

  {

   d=d+2*x+1;

  }

  else

  {

   y--;

   d=d+2*(x-y)+1;

  }

  draw_circle1(xc, yc, x, y);

 }

 return 0;

}

int draw_circle1(int x0, int y0, int x, int y)

{

 putpixel(x0-x, y0-y, BLUE);

 putpixel(x0+x, y0-y, BLUE);

 return 0;

}

Armstrong program in Java using object

Java program with object will do the sum of 1 + 1/4 + 1/7 + 1/9 + ........ + 1/n

Comment your views on this Article :)


Thank you for visiting my blog :)

No comments

Comment your views on this article

Powered by Blogger.