Design A Screen saver in c on Moving Train with Side view.

2,960 views
2,698 views

Published on

This will help you to design of moving train in c/c++ language.

Published in: Education, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
2,960
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
69
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Design A Screen saver in c on Moving Train with Side view.

  1. 1. /*coded by: Sanjay Kumar cahkravarti*/#include <graphics.h>#include <stdlib.h>#include <iostream.h>#include <conio.h>#include<dos.h>#include<process.h>#include<math.h>int x;voidsky_frame();void frame();void side(int);void wheel(int);void wheel1(int);void bulb(int);voidfront_engine(int);voidhot_engine(int);voidvapour_hole(int);void bird(int);voidw_pipe(int);voidr_pipe(int);voidgray_side(int);voidfront_plate(int);void track();void boggy(int);void smoke(int);void sun();void horn();void train(inti){
  2. 2. front_engine(i);}void horn(){x+=20;sound(50+x);delay(1000);}voidgray_side(inti){int poly[8]={310+i,300,310+i,315,200+i,315,200+i,300};setcolor(DARKGRAY);setfillstyle(1,DARKGRAY);fillpoly(4,poly);setcolor(15);line(210+i,220,310+i,220);line(210+i,222,308+i,222);line(308+i,222,308+i,325);line(310+i,220,310+i,325);line(310+i,325,308+i,325);}void sun(){circle(500,70,50);setfillstyle(1,LIGHTRED);floodfill(500,70,15);}voidsky_frame(){int x=getmaxx();int poly[8]={0,0,x,0,x,225,0,225};setfillstyle(1,11);fillpoly(4,poly);
  3. 3. }voidfront_engine(inti) {int poly[8]={360+i,150,450+i,150,450+i,300,360+i,300};setfillstyle(5,4);fillpoly(4,poly);int poly1[8]={210+i,170,230+i,170,230+i,130,210+i,130};setfillstyle(1,0);fillpoly(4,poly1);}void main(){intgd=DETECT,gm;initgraph(&gd,&gm,"c:Turboc3bgi");for(inti=0;i<=500;i++){delay(500);if(kbhit()){exit(0);}frame();track();wheel(i);sky_frame();sun();bird(i);train(i);side(i);hot_engine(i);vapour_hole(i);bulb(i);
  4. 4. w_pipe(i);r_pipe(i);gray_side(i);front_plate(i);boggy(i);smoke(i);if(i%50==0){horn();}}}void smoke(inti) {arc(220+i,120,180,345,10);arc(230+i,115,275,90,10);arc(220+i,110,12,160,10);arc(210+i,115,90,270,10);arc(180+i,110,180,345,10);arc(190+i,105,275,90,10);arc(180+i,100,12,160,10);arc(170+i,105,90,270,10);setfillstyle(1,7);floodfill(220+i,120,15);floodfill(180+i,100,15);}void boggy(inti){int poly[8]={0+i,170,190+i,170,190+i,300,0+i,300};setfillstyle(11,6);fillpoly(4,poly);int poly1[8]={0+i,170,15+i,180,15+i,300,0+i,300};
  5. 5. setfillstyle(10,14);fillpoly(4,poly1);line(0+i,170,15+i,300);line(15+i,180,0+i,300);int poly2[8]={190+i,170,175+i,180,175+i,300,190+i,300};setfillstyle(10,14);fillpoly(4,poly2);int poly3[8]={15+i,180,175+i,180,175+i,300,15+i,300};setfillstyle(9,9);fillpoly(4,poly3);//area for train namingint poly4[10]={15+i,195,175+i,195,175+i,210,15+i,210,15+i,195};drawpoly(5,poly4);outtextxy(25+i,200,"BACKDOOR EXPRESS");//doorint poly5[8]={120+i,220,160+i,220,160+i,280,120+i,280};setfillstyle(1,11);fillpoly(4,poly5);int poly6[8]={120+i,220,155+i,225,155+i,280,120+i,280};setfillstyle(10,10);fillpoly(4,poly6);//drawing windowsint poly7[8]={20+i,220,60+i,220,60+i,250,20+i,250};setfillstyle(1,11);fillpoly(4,poly7);int poly8[8]={65+i,220,105+i,220,105+i,250,65+i,250};setfillstyle(1,11);fillpoly(4,poly8);//windows line
  6. 6. line(20+i,227,60+i,227);line(20+i,234,60+i,234);line(20+i,241,60+i,241);line(20+i,248,60+i,248);line(65+i,227,105+i,227);line(65+i,234,105+i,234);line(65+i,241,105+i,241);line(65+i,248,105+i,248);//boggy inner plate drawingint poly9[8]={0+i,300,10+i,320,190+i,320,190+i,300};setfillstyle(1,DARKGRAY);fillpoly(4,poly9);//boggy connectionint poly10[8]={185+i,250,200+i,250,200+i,255,185+i,255};setfillstyle(1,6);fillpoly(4,poly10);}void track(){int x=getmaxx();int poly[8]={0,350,x,350,x,375,0,375};setfillstyle(9,6);fillpoly(4,poly);int poly1[8]={10,350,10,375,13,375,13,350};setfillstyle(1,0);fillpoly(4,poly1);int poly2[8]={18,350,18,375,21,375,21,350};fillpoly(4,poly2);
  7. 7. }voidfront_plate(inti){int poly[8]={360+i,295,380+i,350,470+i,350,490+i,295};setfillstyle(7,LIGHTGRAY);fillpoly(4,poly);}voidr_pipe(inti){int poly[16]={400+i,218,400+i,223,424+i,285,424+i,295,426+i,295,426+i,285,402+i,223,402+i,218};setcolor(CYAN);setfillstyle(1,CYAN);fillpoly(8,poly);int poly1[16]={458+i,218,458+i,223,428+i,285,428+i,295,430+i,295,430+i,285,460+i,223,460+i,218};fillpoly(8,poly1);int poly2[12]={445+i,230,445+i,233,482+i,233,482+i,295,485+i,295,485+i,230};setcolor(RED);setfillstyle(1,15);fillpoly(6,poly2);int poly3[8]={485+i,295,485+i,300,310+i,300,310+i,295};setcolor(15);setfillstyle(1,15);fillpoly(4,poly3);}voidw_pipe(inti){setcolor(15);line(390+i,220,470+i,220);line(390+i,222,470+i,222);line(390+i,220,360+i,260);line(390+i,222,362+i,260);line(390+i,221,361+i,260);
  8. 8. line(360+i,342,360+i,260);line(362+i,340,362+i,260);line(362+i,340,375+i,340);line(360+i,342,375+i,342);line(375+i,340,375+i,342);line(470+i,220,502+i,260);line(470+i,222,500+i,260);line(470+i,221,501+i,260);line(500+i,260,500+i,340);line(502+i,260,502+i,342);line(500+i,340,475+i,340);line(502+i,342,475+i,342);line(475+i,342,475+i,340);setfillstyle(1,15);floodfill(395+i,221,15);floodfill(487+i,341,15);floodfill(365+i,341,15);}void bird(inti){setcolor(0);arc(600-i,80,45,90,10);arc(614-i,80,90,135,10);arc(580-i,70,45,90,10);arc(594-i,70,90,135,10);arc(560-i,90,45,90,10);arc(574-i,90,90,135,10);arc(400-i,80,45,90,10);arc(414-i,80,90,135,10);arc(480-i,70,45,90,10);
  9. 9. arc(494-i,70,90,135,10);arc(460-i,90,45,90,10);arc(474-i,90,90,135,10);arc(200-i,80,45,90,10);arc(214-i,80,90,135,10);arc(180-i,70,45,90,10);arc(194-i,70,90,135,10);arc(160-i,90,45,90,10);arc(174-i,90,90,135,10);}void frame(){int x=getmaxx(),y=getmaxy();int poly[8]={0,0,x,0,x,y,0,y};setfillstyle(1,0);fillpoly(4,poly);}void side(inti) {int poly[8]={360+i,150,200+i,165,200+i,300,360+i,300};setfillstyle(1,4);setcolor(0);fillpoly(4,poly);}void bulb(inti) {setcolor(15);circle(405+i,165,10);circle(405+i,165,2);setfillstyle(9,14);
  10. 10. floodfill(405+i,165,15);setfillstyle(1,15);floodfill(408+i,165,15);}voidhot_engine(inti) {int poly[10]={350+i,165,350+i,275,310+i,275,310+i,165};int poly1[10]={352+i,163,352+i,277,308+i,277,308+i,163,352+i,163};int poly2[10]={351+i,164,351+i,276,309+i,276,309+i,164,351+i,164};setcolor(LIGHTRED);fillpoly(4,poly);drawpoly(5,poly1);drawpoly(5,poly2);setcolor(0);for(int j=0;j<19;j++){line(312+i+2*j,168,312+i+2*j,275);line(312+i,168,348+i,168);}setcolor(15);rectangle(210+i,270,310+i,280);setfillstyle(1,15);floodfill(250+i,275,15);}voidvapour_hole(inti){int poly[8]={260+i,165,270+i,165,270+i,170,260+i,170};int poly1[8]={260+i,175,270+i,175,270+i,180,260+i,180};int poly2[8]={260+i,185,270+i,185,270+i,190,260+i,190};int poly3[8]={243+i,165,253+i,165,253+i,170,243+i,170};int poly4[8]={243+i,175,253+i,175,253+i,180,243+i,180};int poly5[8]={243+i,185,253+i,185,253+i,190,243+i,190};
  11. 11. int poly6[8]={226+i,165,236+i,165,236+i,170,226+i,170};int poly7[8]={226+i,175,236+i,175,236+i,180,226+i,180};int poly8[8]={226+i,185,236+i,185,236+i,190,226+i,190};int poly9[8]={209+i,167,219+i,167,219+i,172,209+i,172};int poly10[8]={209+i,177,219+i,177,219+i,182,209+i,182};int poly11[8]={209+i,187,219+i,187,219+i,192,209+i,192};setfillstyle(9,8);fillpoly(4,poly);fillpoly(4,poly1);fillpoly(4,poly2);fillpoly(4,poly3);fillpoly(4,poly4);fillpoly(4,poly5);fillpoly(4,poly6);fillpoly(4,poly7);fillpoly(4,poly7);fillpoly(4,poly8);fillpoly(4,poly9);fillpoly(4,poly10);fillpoly(4,poly11);}void wheel(inti){//setcolor(DARKGRAY);circle(340+i,335,40);circle(340+i,335,18);circle(340+i,335,41);circle(340+i,335,19);circle(340+i,335,42);
  12. 12. circle(340+i,335,17);setfillstyle(4,DARKGRAY);floodfill(340+i,355,15);floodfill(340+i,314,15);setfillstyle(1,DARKGRAY);floodfill(340+i,335,15);circle(240+i,335,40);circle(240+i,335,18);circle(240+i,335,41);circle(240+i,335,19);circle(240+i,335,42);circle(240+i,335,17);setfillstyle(4,DARKGRAY);floodfill(240+i,355,15);floodfill(240+i,314,15);setfillstyle(1,DARKGRAY);floodfill(240+i,335,15);circle(140+i,335,40);circle(140+i,335,18);circle(140+i,335,41);circle(140+i,335,19);circle(140+i,335,42);circle(140+i,335,17);setfillstyle(4,DARKGRAY);floodfill(140+i,355,15);floodfill(140+i,314,15);setfillstyle(1,DARKGRAY);floodfill(140+i,335,15);circle(40+i,335,40);
  13. 13. circle(40+i,335,18);circle(40+i,335,41);circle(40+i,335,19);circle(40+i,335,42);circle(40+i,335,17);setfillstyle(4,DARKGRAY);floodfill(40+i,355,15);floodfill(40+i,314,15);setfillstyle(1,DARKGRAY);floodfill(40+i,335,15);}

×