Creating a Rainbow using Graphics Programming in C Last Updated : 11 Sep, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report 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: C // A C program to make a rainbow. This program would only // work in Turbo C compiler in DOS compatible machine #include<stdio.h> #include<graphics.h> #include<dos.h> // function for making of rainbow void rainbow() { // auto detection int gdriver = DETECT,gmode; int x, y, i; // initialize graphics mode(passed three arguments to // initgraph function) // &gdriver is the address of gdriver variable, &gmode is // the address of gmode and // "C:\\Turboc3\\BGI" is the directory path where BGI files are stored initgraph(&gdriver,&gmode,"C:\\Turboc3\\BGI"); x = getmaxx() / 2;//finding centre x-ordinate of screen y = getmaxy() / 2;//finding centre y-ordinate of screen for (i=30; i<200; i++) { // delay function under dos.h for holding the // function for some time delay(100); // selecting color for making of rainbow setcolor(i/10); // making of arc with fixed centre and increasing radius arc(x, y, 0, 180, i-10); } } // driver program int main() { rainbow(); return 0; } Reference:http://www.xcnotes.com/graphics-in-c-language/draw-rainbow-in-c Comment More infoAdvertise with us Next Article How to create GUI in C programming using GTK Toolkit K kartik Improve Article Tags : C Language computer-graphics C-Library Similar Reads C Program to create a House using Graphics Prerequisite: graphics.h, How to include graphics.h in CodeBlocks? The task is to write C program to create a house using graphics. To run the program we have the include the below header file: #include <graphic.h> Setting Up the Environment: Download the WinBGlm zip file from this link. Extra 3 min read Draw a Chess Board using Graphics Programming in C Prerequisite: graphics.h, How to include graphics.h in CodeBlocks? In Computer Graphics, we use graphics.h which provide direct functions to draw different coordinate shapes(like circle, rectangle etc). By using these functions we can draw different objects like car, hut, trees etc. In this program, 4 min read Basic Graphic Programming in C++ Introduction So far we have been using C language for simple console output only.  Most of us are unaware that using C++, low level graphics program can also be made. This means we can incorporate shapes,colors and designer fonts in our program. This article deals with the steps to enable the DevC++ 2 min read How to create GUI in C programming using GTK Toolkit Introduction to GTK Many programming languages bolster GUI improvement as one of the centrepieces of its language highlights. C has no such library connected to it like the string library, IO library, etc, that we every now and again use. This weakness opened the skyline for engineers to pick from a 7 min read Program To Create Keypad Mobile Using Computer Graphics In Turbo C graphics, the graphics.h functions are used to draw different shapes like a circle, rectangle, etc, display text(any message) in different formats (different fonts and colors). By using graphics.h programs, animations, and also games can be designed. These can be useful for beginners. Fun 6 min read Draw a smiley face using Graphics in C language Prerequisite: graphics.h, How to include graphics.h in CodeBlocks? The task is to write a C program to draw a smiley face using graphics in C.To run the program we have the include the below header file: #include <graphic.h> Approach: We will create a Smiley Face with the help below functions: 2 min read Like