|
| 1 | +#include <stdio.h> |
| 2 | +#include <graphics.h> |
| 3 | + |
| 4 | +int main() |
| 5 | +{ |
| 6 | + int gd = DETECT, gm; |
| 7 | + int i, maxx, midy; |
| 8 | + |
| 9 | + /* initialize graphic mode */ |
| 10 | + initgraph(&gd, &gm, "NULL"); |
| 11 | + /* maximum pixel in horizontal axis */ |
| 12 | + maxx = getmaxx(); |
| 13 | + /* mid pixel in vertical axis */ |
| 14 | + midy = getmaxy()/2; |
| 15 | + |
| 16 | + for (i=0; i < maxx-150; i=i+5)/* loop is run for showing the animation */ |
| 17 | + { |
| 18 | + /* clears screen */ |
| 19 | + cleardevice(); |
| 20 | + |
| 21 | + /* draw a white road */ |
| 22 | + setcolor(WHITE);/* color of the road */ |
| 23 | + line(0, midy + 37, maxx, midy + 37); |
| 24 | + |
| 25 | + /* Draw Car */ |
| 26 | + setcolor(YELLOW);/* color of the car body */ |
| 27 | + |
| 28 | + /* car body */ |
| 29 | + line(i, midy + 23, i, midy);/* draws the left most line parallel to y-axis */ |
| 30 | + line(i, midy, 40 + i, midy - 20); |
| 31 | + line(40 + i, midy - 20, 80 + i, midy - 20);/* draws the roof of the car*/ |
| 32 | + line(80 + i, midy - 20, 100 + i, midy);/* draws the front mirror part of the car */ |
| 33 | + line(100 + i, midy, 120 + i, midy); |
| 34 | + line(120 + i, midy, 120 + i, midy + 23); |
| 35 | + line(0 + i, midy + 23, 18 + i, midy + 23); |
| 36 | + arc(30 + i, midy + 23, 0, 180, 12);/* draws the arc to accomodate the wheels */ |
| 37 | + line(42 + i, midy + 23, 78 + i, midy + 23); |
| 38 | + arc(90 + i, midy + 23, 0, 180, 12);/* draws the arc to accomodate the wheels */ |
| 39 | + line(102 + i, midy + 23, 120 + i, midy + 23); |
| 40 | +/* car body ends */ |
| 41 | + |
| 42 | +/* Draw Windows */ |
| 43 | +/* left window */ |
| 44 | + line(28 + i, midy, 43 + i, midy - 15);/* left part of left window */ |
| 45 | + line(43 + i, midy - 15, 57 + i, midy - 15);/* roof of the left window */ |
| 46 | + line(57 + i, midy - 15, 57 + i, midy);/* right part of left window */ |
| 47 | + line(57 + i, midy, 28 + i, midy);/* bottom part of the left window */ |
| 48 | +/* left window ends */ |
| 49 | + |
| 50 | +/* right window */ |
| 51 | + line(62 + i, midy - 15, 77 + i, midy - 15);/* left part of right window */ |
| 52 | + line(77 + i, midy - 15, 92 + i, midy);/* roof of the rightt window */ |
| 53 | + line(92 + i, midy, 62 + i, midy);/* right part of right window */ |
| 54 | + line(62 + i, midy, 62 + i, midy - 15);/* bottom part of the right window */ |
| 55 | +/* right window ends */ |
| 56 | + |
| 57 | + floodfill(5 + i, midy + 22, YELLOW);/* fills the whole car body with yellow color */ |
| 58 | + |
| 59 | + setcolor(BLUE);/* color of the wheels */ |
| 60 | + /* Draw Wheels */ |
| 61 | + circle(30 + i, midy + 25, 9); |
| 62 | + circle(90 + i, midy + 25, 9); |
| 63 | + floodfill(30 + i, midy + 25, BLUE);/* fills the left wheel with blue color */ |
| 64 | + floodfill(90 + i, midy + 25, BLUE);/* fills the right wheel with blue color */ |
| 65 | + |
| 66 | + /* Add delay of 0.1 milli seconds */ |
| 67 | + delay(100);/* to observe the animation */ |
| 68 | + } |
| 69 | + |
| 70 | + getch(); |
| 71 | + closegraph(); |
| 72 | + return 0; |
| 73 | +} |
0 commit comments