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:
// 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
This article is contributed by Shivam Pradhan (anuj_charm). If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
Recommended Posts:
- Draw a moving car using computer graphics programming in C
- Draw a Chess Board using Graphics Programming in C
- Sierpinski Triangle using Graphics
- Flood fill algorithm using C graphics
- Mandlebrot Set in C/C++ Using Graphics
- How to create a Heart using C Graphics
- C Program to create a House using Graphics
- Draw a smiley face using Graphics in C language
- Represent Tree using graphics in C/C++
- DDA Line generation Algorithm in Computer Graphics
- Point Clipping Algorithm in Computer Graphics
- How to add "graphics.h" C/C++ library to gcc compiler in Linux
- 2D Transformation in Computer Graphics | Set 1 (Scaling of Objects)
- Translation of objects in computer graphics
- Vector vs Raster Graphics
- Draw ellipse in C graphics
- Draw a line in C++ graphics
- Draw Rectangle in C graphics
- Draw circle in C graphics
- How to include graphics.h in CodeBlocks?
Improved By : MuhammedYasir

