C programme to draw a Rainbow

In C Graphics we use graphics.h functions. This is used to draw different shapes(like circle,rectangle etc),display text(any message)in different format(different fonts and colors).By using graphics.h we can make programs, animations and also games. We have to call initgraph function which will initialize the graphics mode.

 

#include<stdio.h>

#include<conio.h>

#include<graphics.h>

#include<dos.h>

void main()

{

//auto detection

       int gdriver = DETECT,gmode;

       int x,y,i;

       //initialize graphics mode(passed three arguments to initgraph function)

       initgraph(&gdriver,&gmode,"C:\\Turboc3\\BGI");/*&gdriver is the address of gdriver variable,&gmodeis the address of gmode and ,"C:\\Turboc3\\BGI" is the path where BGI files are stored.*/

          x=getmaxx()/2;

           y=getmaxy()/2;

           for(i=30;i<200;i++)

              {

                       delay(100);

                        setcolor(i/10);

                         arc(x,y,0,180,i-10);

                }

getch();

}

rainbow in c

Explanation..

DETECT is a macro defined in graphics.h which requests initgraph() method to automatically determine which graphics driver to load.

Getmaxx() This function is used only to get the maximum value of X coordinate

Getmaxy() This function is used only to get the maximum value of Y coordinate.

About Us

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