Introduction :
Using C or C++ graphics programming language, creating a moving bicycle animation project is very interesting and exciting for new developers. You can use various functions of the graphics.h library in Turbo C++ IDE to develop such program. With the help of C or C++ language, you can draw a moving bicycle on the graphics screen. In this article, I shall show you how to create moving bicycle by C or C++ graphics programming language.
About the program :
This is an animation program of a moving bicycle. It is built by C or C++ programming language. I create the moving bicycle program in Turbo C++ IDE with the help of graphics.h library. When you run the program on your PC, you can see a bicycle moving from left to the right side of the graphics screen. After that, you have to press any key to stop the program.
Explanation of the program :
First, you have to include the libraries such as graphics.h, conio.h and dos.h in the program. Then, declare integer variables such as “x”, “y”, “i”, “r”, “graphic_driver” and “graphic_mode” in the main() function. After that, you have to call initgraph() function to initialize the graphics mode. To calculate the center coordinates (x and y) of the screen, you can use getmaxx() and getmaxy() function.
Now, set the background color of the graphics screen using setbkcolor() function. In the for loop, draw the different parts (wheels, frame, seat, handlebars and pedals) of the bicycle using circle(), line(), rectangle() and arc() functions. Here, you have to call setcolor() function to set the drawing color for the bicycle.
In the loop, you have to update the position of the bicycle and redraw it at a new position. You can use delay() function to control the animation speed and cleardevice() to clear the screen. The getch() and closegraph() functions are used to take a key press from users and closes the graphics mode.
How run the program :
First, you have to open Turbo C++ IDE. If you have not installed Turbo C++ IDE in your PC, install it. After install Turbo C++ IDE, create a C or C++ file in Turbo C++ IDE. Now, copy the source code of the program and paste in the C or C++ file. If you do not know how copy paste in Turbo C++ IDE, click here. You have to also know how to use graphics.h library in Turbo C++ IDE. Then, run the program and see the output in your PC.
Source code :
Here, you see the source code of moving bicycle animation program. You can copy the following code and use it in your project.
/*Developed by Puskar Jasu*/
#include <graphics.h>
#include <conio.h>
#include <dos.h>
int main(void)
{
int x, y, i, r = 20;
int graphic_driver = DETECT, graphic_mode;
initgraph(&graphic_driver, &graphic_mode, "//turboc3/bgi");
x = getmaxx() / 2;
y = getmaxy() / 2;
setbkcolor(4);
for (i = 0; i <= x + x; i++)
{
setcolor(14);
circle(i, y + y - 40, r);
line(i, y + y - 40, i, y + y - 70);
rectangle(i - 10, y + y - 75, i + 10, y + y - 70);
line(i, y + y - 70, i + 100, y + y - 70);
line(i + 10, y + y - 70, i + 50, y + y - 40);
line(i + 50, y + y - 40, i + 90, y + y - 70);
line(i + 25, y + y - 80, i + 30, y + y - 90);
line(i + 25, y + y - 80, i + 50, y + y - 85);
line(i + 50, y + y - 85, i + 30, y + y - 90);
line(i + 35, y + y - 70, i + 35, y + y - 80);
arc(i, y + y - 40, 20, 160, 25);
circle(i + 100, y + y - 40, r);
line(i + 100, y + y - 40, i + 100, y + y - 80);
line(i + 80, y + y - 85, i + 120, y + y - 75);
circle(i + 50, y + y - 40, 10);
arc(i + 100, y + y - 40, 20, 160, 25);
delay(50);
cleardevice();
}
getch();
closegraph();
return 0;
}
Output of the program :
When you run the program, you can see the output of the moving bicycle animation program on your PC. You can see the output in my YouTube channel.
Conclusion :
At last, you have learned how to build moving bicycle animation program in C or C++ programming language. You can use the code in your project. Thank you for visiting my site.