In computer graphics, 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, we will draw a moving car using line and circles.
Functions used in program:
- delay(n): This function is used for holding the program output for a small period of time since processing is very fast so use it to see the result.
- setcolor(n): A function from graphics.h header file which set the color of the pointer (cursor). There are some predefined colors in computer graphics. Here n is color number.
- line(x1, y1, x2, y2): A function from graphics.h header file which draw a line with (x1, y1) as first coordinate of line and (x2, y2) as second coordinate of the line.
- circle(x, y, r): A function from graphics.h header file which draw a circle with center (x, y) and radius r.
Example 1: This example create a moving car without using cleardevice() method.
Example 2: This example uses cleardevice() method to clear the screen.
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Draw circle in C graphics
- Draw ellipse in C graphics
- Draw Rectangle in C graphics
- Draw a line in C++ graphics
- Draw an Ellipse rotating over a Circle in C++ graphics
- Applications of Computer Graphics
- Segments in Computer Graphics
- Computer Graphics | Antialiasing
- Computer Graphics | The RGB color model
- Translation of objects in computer graphics
- Display Processor in Computer Graphics
- Creating a Rainbow using Graphics Programming in C
- DDA Line generation Algorithm in Computer Graphics
- Point Clipping Algorithm in Computer Graphics
- 2D Transformation in Computer Graphics | Set 1 (Scaling of Objects)
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.