COMPUTER GRAPHICS - Mini Project - Moving Car using Computer graphics

Project Name -  Moving Car using Computer graphics

Software Code :-

#include <stdio.h>

#include <graphics.h>

#include <conio.h>

#include <dos.h>


int main() {

intgd = DETECT, gm;

inti, maxx, midy;

initgraph(&gd, &gm, "c:\\turboc3\\bgi");

maxx = getmaxx();

midy = getmaxy()/2;


    for (i=0; i< maxx-150; i=i+5) {

cleardevice();


        /* draw a white road */

setcolor(WHITE);

        line(0, midy + 37, maxx, midy + 37);



setcolor(YELLOW);

setfillstyle(SOLID_FILL, RED);


        line(i, midy + 23, i, midy);

        line(i, midy, 40 + i, midy - 20);

        line(40 + i, midy - 20, 80 + i, midy - 20);

        line(80 + i, midy - 20, 100 + i, midy);

        line(100 + i, midy, 120 + i, midy);

        line(120 + i, midy, 120 + i, midy + 23);

        line(0 + i, midy + 23, 18 + i, midy + 23);

        arc(30 + i, midy + 23, 0, 180, 12);

        line(42 + i, midy + 23, 78 + i, midy + 23);

        arc(90 + i, midy + 23, 0, 180, 12);

        line(102 + i, midy + 23, 120 + i, midy + 23);

        line(28 + i, midy, 43 + i, midy - 15);

        line(43 + i, midy - 15, 57 + i, midy - 15);

        line(57 + i, midy - 15, 57 + i, midy);

        line(57 + i, midy, 28 + i, midy);

        line(62 + i, midy - 15, 77 + i, midy - 15);

        line(77 + i, midy - 15, 92 + i, midy);

        line(92 + i, midy, 62 + i, midy);

        line(62 + i, midy, 62 + i, midy - 15);

floodfill(5 + i, midy + 22, YELLOW);

setcolor(BLUE);

setfillstyle(SOLID_FILL, DARKGRAY);

        circle(30 + i, midy + 25, 9);

        circle(90 + i, midy + 25, 9);

floodfill(30 + i, midy + 25, BLUE);

floodfill(90 + i, midy + 25, BLUE);

        delay(100);

    }

getch();

closegraph();

    return 0;

}


Output:-
2020-12-04 (1).png

*The car moves in the output.


The abbreviations and the definitions of the list of graphic functions used are:

  1. Initgraph:- It initializes the graphics system by loading the passed graphics driver then changing the system into graphics mode.

  2. Getmaxx:- It returns the maximum X coordinate in current graphics mode and driver.

  3. Setcolor:- It changes the current drawing colour. Default colour is white. Each color is assigned a number, like BLACK is 0 and RED is 4. Here we are using colour constants defined inside graphics.h header file.

  4. Setfillstyle:- It sets the current fill pattern and fill color.

  5. Circle:- It draws a circle with radius r and centre at (x, y).

  6. Floodfill:- It is used to fill a closed area with current fill pattern and fill color. It takes any point inside closed area and color of the boundary as input.

  7. Cleardevice:- It clears the screen, and sets current position to (0, 0).

  8. Kbhit:- It is used to determine whether a key is pressed or not. It returns a non-zero value if a key is pressed otherwise zero.

  9. Delay:- It is used to suspend execution of a program for a M milliseconds.

  10. Closegraph:- It unloads the graphics drivers and sets the screen back to text mode.

Comments