How To Draw Scenery Animation in C or C++ (Computer Graphics)

  PROJECT BY

(SIMPLIFY LEARN PROGRAMMING) 

ON

SCENERY ANIMATION


SOURCE CODE:


#include<iostream.h>

#include<conio.h>

#include<graphics.h>

#include<dos.h>

void main()

{

int gd=DETECT,gm,i;

initgraph(&gd,&gm,"C:\\TC\\BGI");                        //Write the Path of BGI Folder

 

//a,b,c,d are used for Translation

int a=200, b=-190;

int c=200, d=-190;

 

//x,y,m,n are used for Scaling.

 

float x=0.5, y=0.5;

float m=0.5, n=0.5;

for(i=0;i<=500;i++)

{

 

//================================= 3 CLOUDS ===============================//

//================================= MIDDLE CLOUD ===========================//

 

ellipse(200,30,60,240,10,15);

ellipse(225,20,345,165,20,15);

ellipse(262,27,340,160,20,15);

ellipse(268,42,230,50,20,10);

ellipse(226,46,163,340,31,15);

ellipse(300,21,20,182,21,19);

ellipse(325,31,290,100,21,15);

ellipse(299,45,228,20,33,11);

 

//================================= LEFT CLOUD =============================//

 

ellipse(40,30,60,240,10,15);

ellipse(65,20,345,165,20,15);

ellipse(105,27,340,160,20,15);

ellipse(109,42,230,50,20,10);

ellipse(66,46,163,340,31,17);

 

//================================= RIGHT CLOUD ============================//

 

ellipse(450,30,60,240,10,15);

ellipse(475,20,345,165,20,15);

ellipse(512,27,340,160,20,15);

ellipse(518,42,230,50,20,10);

ellipse(476,46,163,340,31,15);

 

//================================= 3 TREES   ==============================//

//================================= 1ST TREE  ==============================//

 

//TREE 1 CROWN

setcolor(WHITE);

setfillstyle(SOLID_FILL,GREEN);

line(240,420,275,420);

line(240,420,245,405);

line(275,420,270,405);

line(245,405,240,405);

line(270,405,275,405);

line(240,405,245,390);

line(275,405,270,390);

line(245,390,240,390);

line(270,390,275,390);

line(240,390,258,370);

line(275,390,257,370);

floodfill(259,375,WHITE);

 

//TREE 1 TRUNK

setcolor(WHITE);

setfillstyle(SOLID_FILL,BROWN);

line(250,460,250,420);

line(265,460,265,420);

line(250,460,265,460);

line(250,420,265,420);

floodfill(255,441,WHITE);

 

//================================= 2ND TREE ===============================//

 

/* THIS TREE IS TRANSLATION (TRANSFORMATION) OF 1ST TREE. */

 

//TREE 2 CROWN

setcolor(WHITE);

setfillstyle(SOLID_FILL,GREEN);

line(240+c,420+d,275+c,420+d);

line(240+c,420+d,245+c,405+d);

line(275+c,420+d,270+c,405+d);

line(245+c,405+d,240+c,405+d);

line(270+c,405+d,275+c,405+d);

line(240+c,405+d,245+c,390+d);

line(275+c,405+d,270+c,390+d);

line(245+c,390+d,240+c,390+d);

line(270+c,390+d,275+c,390+d);

line(240+c,390+d,258+c,370+d);

line(275+c,390+d,257+c,370+d);

floodfill(259+c,375+d,WHITE);

 

//TREE 2 TRUNK

setcolor(WHITE);

setfillstyle(SOLID_FILL,BROWN);

line(250+c,460+d,250+c,420+d);

line(265+c,460+d,265+c,420+d);

line(250+c,460+d,265+c,460+d);

line(250+c,420+d,265+c,420+d);

floodfill(255+c,441+d,WHITE);

 

//================================= 3RD TREE ===============================//

 

/* THIS TREE IS SCALING (TRANSFORMATION) OF 1ST TREE. */

 

//TREE 3 CROWN

setcolor(WHITE);

setfillstyle(SOLID_FILL,GREEN);

line(240*m,420*n,275*m,420*n);

line(240*m,420*n,245*m,405*n);

line(275*m,420*n,270*m,405*n);

line(245*m,405*n,240*m,405*n);

line(270*m,405*n,275*m,405*n);

line(240*m,405*n,245*m,390*n);

line(275*m,405*n,270*m,390*n);

line(245*m,390*n,240*m,390*n);

line(270*m,390*n,275*m,390*n);

line(240*m,390*n,258*m,370*n);

line(275*m,390*n,257*m,370*n);

floodfill(259*m,375*n,WHITE);

 

//TREE 3 TRUNK

setcolor(WHITE);

setfillstyle(SOLID_FILL,BROWN);

line(250*m,460*n,250*m,420*n);

line(265*m,460*n,265*m,420*n);

line(250*m,460*n,265*m,460*n);

line(250*m,420*n,265*m,420*n);

floodfill(255*m,441*n,WHITE);

 

 

//================================= 3 HOUSES ===============================//

//================================= 1ST HOUSE ==============================//

 

//TRIANGLE OF HOUSE 1

 

setcolor(WHITE);

setfillstyle(SOLID_FILL,BROWN);

line(88,400,163,400);

line(100,370,88,400);

line(100,370,112,400);

line(100,370,150,370);

line(150,370,163,400);

floodfill(100,375,WHITE);

 

setcolor(WHITE);

setfillstyle(SOLID_FILL,BROWN);

line(88,400,163,400);

line(100,370,112,400);

line(100,370,112,400);

line(100,370,150,370);

line(150,370,163,400);

floodfill(105,375,WHITE);

 

setcolor(WHITE);

setfillstyle(SOLID_FILL,5);

line(112,400,112,440);

line(88,440,112,440);

line(88,400,88,440);

line(112,440,163,440);

floodfill(90,402,WHITE);

 

setcolor(WHITE);

setfillstyle(SOLID_FILL,5);

line(163,400,163,440);

line(112,440,163,440);

line(112,400,112,440);

line(88,400,163,400);

floodfill(115,405,WHITE);

 

//1ST HOUSE DOOR

setcolor(WHITE);

setfillstyle(SOLID_FILL,RED);

line(94,440,94,420);

line(106,440,106,420);

line(94,420,106,420);

floodfill(97,435,WHITE);

 

//================================= 2ND HOUSE ==============================//

 

/* THIS HOUSE IS TRANSLATION (TRANSFORMATION) OF 1ST TREE. */

 

//TRIANGLE OF HOUSE 2

setcolor(WHITE);

setfillstyle(SOLID_FILL,YELLOW);

line(88+a,400+b,163+a,400+b);

line(100+a,370+b,88+a,400+b);

line(100+a,370+b,112+a,400+b);

line(100+a,370+b,150+a,370+b);

line(150+a,370+b,163+a,400+b);

floodfill(100+a,375+b,WHITE);

 

setcolor(WHITE);

setfillstyle(SOLID_FILL,YELLOW);

line(88+a,400+b,163+a,400+b);

line(100+a,370+b,112+a,400+b);

line(100+a,370+b,112+a,400+b);

line(100+a,370+b,150+a,370+b);

line(150+a,370+b,163+a,400+b);

floodfill(105+a,375+b,WHITE);

 

setcolor(WHITE);

setfillstyle(SOLID_FILL,1);

line(112+a,400+b,112+a,440+b);

line(88+a,440+b,112+a,440+b);

line(88+a,400+b,88+a,440+b);

line(112+a,440+b,163+a,440+b);

floodfill(90+a,402+b,WHITE);

 

setcolor(WHITE);

setfillstyle(SOLID_FILL,1);

line(163+a,400+b,163+a,440+b);

line(112+a,440+b,163+a,440+b);

line(112+a,400+b,112+a,440+b);

line(88+a,400+b,163+a,400+b);

floodfill(115+a,405+b,WHITE);

 

//2ND HOUSE DOOR

setcolor(WHITE);

setfillstyle(SOLID_FILL,BROWN);

line(94+a,440+b,94+a,420+b);

line(106+a,440+b,106+a,420+b);

line(94+a,420+b,106+a,420+b);

floodfill(97+a,435+b,WHITE);

 

//================================= 3RD HOUSE ==============================//

 

/* THIS HOUSE IS SCALING (TRANSFORMATION) OF 1ST TREE. */

 

//TRIANGLE OF HOUSE 3

setcolor(WHITE);

setfillstyle(SOLID_FILL,LIGHTBLUE);

line(88*x,400*y,163*x,400*y);

line(100*x,370*y,88*x,400*y);

line(100*x,370*y,112*x,400*y);

line(100*x,370*y,150*x,370*y);

line(150*x,370*y,163*x,400*y);

floodfill(100*x,375*y,WHITE);

 

setcolor(WHITE);

setfillstyle(SOLID_FILL,LIGHTBLUE);

line(88*x,400*y,163*x,400*y);

line(100*x,370*y,112*x,400*y);

line(100*x,370*y,112*x,400*y);

line(100*x,370*y,150*x,370*y);

line(150*x,370*y,163*x,400*y);

floodfill(105*x,375*y,WHITE);

 

setcolor(WHITE);

setfillstyle(SOLID_FILL,4);

line(112*x,400*y,112*x,440*y);

line(88*x,440*y,112*x,440*y);

line(88*x,400*y,88*x,440*y);

line(112*x,440*y,163*x,440*y);

floodfill(90*x,402*y,WHITE);

 

setcolor(WHITE);

setfillstyle(SOLID_FILL,4);

line(163*x,400*y,163*x,440*y);

line(112*x,440*y,163*x,440*y);

line(112*x,400*y,112*x,440*y);

line(88*x,400*y,163*x,400*y);

floodfill(115*x,405*y,WHITE);

 

//3RD HOUSE DOOR

setcolor(WHITE);

setfillstyle(SOLID_FILL,YELLOW);

line(94*x,440*y,94*x,420*y);

line(106*x,440*y,106*x,420*y);

line(94*x,420*y,106*x,420*y);

floodfill(97*x,435*y,WHITE);

 

 

//================================= MOUNTAIN ===============================//

 

//1ST TRIANGLE

setcolor(WHITE);              //BOUNDARY COLOR OF MOUNTAIN

setfillstyle(SOLID_FILL,GREEN); //ACTUAL COLOR OF MOUNTAIN

line(0,150,100,75);

line(100,75,200,150);

 

//2ND TRIANGLE

setcolor(WHITE);

setfillstyle(SOLID_FILL,GREEN);

line(175,131,275,75);

line(275,75,375,150);

 

//3RD TRIANGLE

setcolor(WHITE);

setfillstyle(SOLID_FILL,GREEN);

line(350,131,450,75);

line(450,75,550,150);

 

//4TH TRIANGLE

setcolor(WHITE);

setfillstyle(SOLID_FILL,GREEN);

line(525,131,600,75);

line(600,75,750,180);

 

line(0,150,750,150);

floodfill(100,136,WHITE);              //BOTTOM LINE OF MOUNTAIN

floodfill(275,136,WHITE);              //2ND TRIANGLE

floodfill(450,136,WHITE);              //3RD TRIANGLE

floodfill(600,136,WHITE);              //4TH TRIANGLE

 

//================================= SUN ====================================//

 

setcolor(WHITE);

setfillstyle(SOLID_FILL,YELLOW);

arc(178,112,0,180,30);

floodfill(171,109,WHITE);

setfillstyle(SOLID_FILL,BLUE);

floodfill(50,50,WHITE);

 

//================================= CAR ====================================//

 

//ROAD

setcolor(WHITE);

line(0,322,700,322);

 

//CAR BODY

setcolor(WHITE);

setfillstyle(SOLID_FILL,4);

line(0+i,300,13+i,298);

line(13+i,298,30+i,280);

line(30+i,280,80+i,280);

line(80+i,280,97+i,298);

line(97+i,298,120+i,300);

line(0+i,300,0+i,315);

line(0+i,315,25+i,315);

arc(35+i,315,0,180,9);

line(45+i,315,67+i,315);

arc(77+i,315,0,180,9);

line(85+i,315,120+i,315);

line(120+i,300,120+i,315);

floodfill(1+i,301,WHITE);

 

//FIRST WINDOW

setcolor(WHITE);

setfillstyle(SOLID_FILL,BLACK);

line(32+i,285,50+i,285);

line(50+i,285,50+i,295);

line(50+i,295,23+i,295);

line(32+i,285,23+i,295);

floodfill(33+i,286,WHITE);

 

//SECOND WINDOW

setcolor(WHITE);

setfillstyle(SOLID_FILL,BLACK);

line(60+i,285,78+i,285);

line(60+i,285,60+i,295);

line(60+i,295,85+i,295);

line(78+i,285,85+i,295);

floodfill(61+i,286,WHITE);

 

//WHEELS

//LEFT WHEELS

setcolor(WHITE);

setfillstyle(SOLID_FILL,BROWN);

circle(35+i,315,6);

floodfill(36+i,314,WHITE);

 

//RIGHT WHEELS

setcolor(WHITE);

setfillstyle(SOLID_FILL,BROWN);

circle(77+i,315,6);

floodfill(76+i,314,WHITE);

delay(40);

cleardevice();

}

getch();

closegraph();

}


OUTPUT:




Comments

Popular posts from this blog

How To Draw a Butterfly Animation in C (Computer Graphics)

How To Create Flying Kite Animation in C Or C++ (Computer Graphics)