The use of for Loops alongwith Graphical function to draw a circle chain

Circle() is used to draw a circle centered at(x,y) with radius specified by the variable radius in the current drawing colour.

 

Animation of graphical features using for loops. The loops are used for moving the particular object from one place to another one the screen

#include<iostream.h>

#include<conio.h>

#include<graphics.h>

#include<dos.h>

 class draw

   {

      private:

             int i,x,y,r;

     public:

             void sketch();

   };

 

void draw::sketch()

 {

     for(x=100;x<=500;x=x+10)

       {

           setcolor(BLUE);

           circle(x,100,20);

            delay(30);

       }

    for(y=100;y<=400;y=y+10)

      {

        setcolor(GREEN);

         circle(500,y,20);

         delay(30);

      }

  for(x=500;x>=100;x=x-10)

    {

       setcolor(RED);

       circle(x,400,20);

       delay(30);

    }

  for(y=400;y>=100;y=y-10)

    {

       setcolor(YELLOW);

       circle(100,y,20);

      delay(30);

    }

}

 

int main()

  {

         clrscr();

        int gd=DETECT,gm;

        draw c;

        clrscr();

         initgraph(&gd,&gm,"c:\\tc\\bgi");

        c.sketch();

        closegraph();

        delay(30);

         return 0;

   }

Explanation…

The above example when executed display a circle chain in sequence form. Similarly the center coordinates can remain same and its radius can be varied.

Draw a circle using for loop

About Us

Rekha SetiaRekha Setia is a passionate blogger of Extra Computer Notes. if you have any ideas or any request me @