Open In App

Draw a moving cycle using computer graphics programming in C/C++

In C graphics, the graphics.h functions are used to draw different shapes like circles, rectangles, etc, display text(any message) in a different format (different fonts and colors). By using the functions in the header graphics.h, programs, animations, and different games can also be made. In this article, let’s discuss how to draw a moving cycle in C using graphics.

Functions used:



Approach: Following are the steps below to generate a moving cycle:

Below is the implementation of the above approach:






// C++ program to draw the moving
// cycle using computer graphics
  
#include <conio.h>
#include <dos.h>
#include <graphics.h>
#include <iostream.h>
  
// Driver code
int main()
{
    int gd = DETECT, gm, i, a;
  
    // Path of the program
    initgraph(&gd, &gm, "C:\\TURBOC3\\BGI");
  
    // Move the cycle
    for (i = 0; i < 600; i++) {
        // Upper body of cycle
        line(50 + i, 405, 100 + i, 405);
        line(75 + i, 375, 125 + i, 375);
        line(50 + i, 405, 75 + i, 375);
        line(100 + i, 405, 100 + i, 345);
        line(150 + i, 405, 100 + i, 345);
        line(75 + i, 345, 75 + i, 370);
        line(70 + i, 370, 80 + i, 370);
        line(80 + i, 345, 100 + i, 345);
  
        // Wheel
        circle(150 + i, 405, 30);
        circle(50 + i, 405, 30);
  
        // Road
        line(0, 436, getmaxx(), 436);
  
        // Stone
        rectangle(getmaxx() - i, 436,
                  650 - i, 431);
  
        // Stop the screen for 10 secs
        delay(10);
  
        // Clear the screen
        cleardevice();
    }
  
    getch();
  
    // Close the graph
    closegraph();
}

Output:


Article Tags :