Creating a Rainbow using Graphics Programming in C
Last Updated :
11 Sep, 2023
In Turbo C graphics we use graphics.h functions 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. These can be useful for beginners.
Functions Used :
- delay(n): A function from dos.h header file is responsible for holding of the program for a while depending upon given value n.
- setcolor(n): A function from graphics.h header file which set the color of pointer(cursor).
- arc(x,y,a1,a2,r): A function from graphics.h header file which draw an arc with (x,y) as centre (a2-a1) as angle and r as radius.
Implementation:
#include<stdio.h>
#include<graphics.h>
#include<dos.h>
void rainbow()
{
int gdriver = DETECT,gmode;
int x, y, i;
initgraph(&gdriver,&gmode, "C:\\Turboc3\\BGI" );
x = getmaxx() / 2;
y = getmaxy() / 2;
for (i=30; i<200; i++)
{
delay(100);
setcolor(i/10);
arc(x, y, 0, 180, i-10);
}
}
int main()
{
rainbow();
return 0;
}
|
Reference:http://www.xcnotes.com/graphics-in-c-language/draw-rainbow-in-c
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...