#include iostream.h
#include conio.h
#include graphics.h
#include math.h
#include dos.h
#define PI 3.141593
int gd=DETECT,gm,xc,yc;
int pst[10],inv[8],ov[8],shaft[8];
void init()
{
int epst[10]={279,109,279,159,359,159,359,109,279,109};
int einv[8]={234,19,289,69,279,79,299,59};
int eov[8]={404,19,349,69,359,79,339,59};
int eshaft[8]={309,159,319,249,329,159,309,159};
for(int i=0;i<10;i++) pst[i]=epst[i];
for(i=0;i<8;i++)
{
inv[i]=einv[i];
ov[i]=eov[i];
shaft[i]=eshaft[i];
}
}
void cyllinder()
{ // static coding
setcolor(6);
setlinestyle(0,0,1);
xc=getmaxx()/2;
yc=getmaxy()/2;
// cout<<"xc: "<
arc(xc,yc+50,120,60,80); //inner arc
arc(xc,yc+50,120,60,90); //outer arc
circle(xc,yc+50,55);
circle(xc,yc+50,65);
circle(xc,yc+50,25);
arc(xc,yc-105,60,120,90); //upper arc
line(xc-45,yc-150,xc-45,yc-27); //left of left
line(xc-40,yc-160,xc-40,yc-20); //right of left
line(xc+45,yc-150,xc+45,yc-27); //right of right
line(xc+40,yc-160,xc+40,yc-20); //left of right
line(xc-45,yc-150,xc-85,yc-150); //lower left
line(xc-40,yc-160,xc-85,yc-160); //upper left
line(xc+45,yc-150,xc+85,yc-150); //lower right
line(xc+40,yc-160,xc+85,yc-160); //upper right
line(xc-85,yc-180,xc+85,yc-180); //upper most
line(xc-15,yc-193,xc-15,yc-180); //spark plug
line(xc+15,yc-193,xc+15,yc-180); // ''
line(xc-8,yc-195,xc-8,yc-180); // ''
line(xc+8,yc-195,xc+8,yc-180); // ''
line(xc-8,yc-195,xc,yc-215); // ''
line(xc+8,yc-195,xc,yc-215); // ''
line(xc-5,yc-180,xc-5,yc-168); // ''
line(xc+5,yc-168,xc-5,yc-168); // ''
line(xc,yc-180,xc,yc-170); // ''
line(xc+5,yc-180,xc+5,yc-170); // ''
line(xc,yc-170,xc+5,yc-170); // ''
setfillstyle(1,4);
floodfill(xc+2,yc-175,6);
line(xc-85,yc-150,xc-85,yc-180); // left stop
line(xc+85,yc-150,xc+85,yc-180); // right stop
setfillstyle(1,6);
floodfill(xc-80,yc-155,6);
}
void drawpst()
{
setlinestyle(0,0,3);
drawpoly(5,pst);
int xh=pst[0];
int yh=pst[1];
line(xh,yh+10,xh+80,yh+10);
line(xh,yh+15,xh+80,yh+15);
}
void drawin()
{
setlinestyle(0,0,3);
drawpoly(4,inv);
}
void drawout()
{
setlinestyle(0,0,3);
drawpoly(4,ov);
}
void drawshaft()
{
setlinestyle(0,0,3);
drawpoly(4,shaft);
setlinestyle(0,0,1);
int xh=shaft[2];
int yh=shaft[3];
circle(xh,yh,5);
int poly[10]={xh-8,yh-6,xh-8,yh+6,xh+8,yh+6,xh+8,yh-6,xh-8,yh-6};
line(xc-5,yc+50,xh-5,yh);
line(xc+5,yc+50,xh+5,yh);
drawpoly(5,poly);
}
void transpst(int t)
{
int k=1;
if(t<0)
{k=-k;t=-t;}
for(int j=0;j
delay(15);
setcolor(0);
drawpst();
for(int i=1;i<10;i+=2)
pst[i]+=k;
setcolor(6);
drawpst();
cyllinder();
}
}
void transin(int t)
{
int k=1;
if(t<0)
{k=-k;t=-t;}
for(int j=0;j
delay(15);
setcolor(0);
drawin();
for(int i=0;i<10;i++)
inv[i]+=k;
setcolor(6);
drawin();
cyllinder();
}
}
void transout(int t)
{
int k=1;
if(t<0)
{k=-k;t=-t;}
for(int j=0;j
delay(15);
setcolor(0);
drawout();
for(int i=0;i<10;i++)
{
ov[i]-=k;
i++;
ov[i]+=k;
}
setcolor(6);
drawout();
cyllinder();
}
}
void transshaft(int t)
{int k=1;
if(t<0)
{k=-k;t=-t;}
float v=0;
for(int j=0;j
double theta=double(v)*(PI/180.0);
delay(15);
setcolor(0);
drawshaft();
for(int i=1;i<8;i+=2)
{if(i==2 || i==3)
continue;
shaft[i]+=k;
}
int xr=xc;
int yr=yc+60;
int x=shaft[2];
int x1=x;
int y=shaft[3];
int y1=y;
x=xr+(x1-xr)*cos(theta)-(y1-yr)*sin(theta);
y=yr+(x1-xr)*sin(theta)+(y1-yr)*cos(theta);
shaft[2]=x;
shaft[3]=y;
v+=3.05;
setcolor(6);
drawshaft();
cyllinder();
}
}
void intake()
{
setcolor(0);
settextstyle(1,0,3);
outtextxy(277,390,"Exhaust");
setcolor(5);
settextstyle(1,0,3);
outtextxy(275,390," Intake");
int xf=xc;
int yf=yc-150;
for(int i=0;i<20;i++)
{
transpst(3);
transshaft(3);
transin(1);
}
transin(-20);
setfillstyle(1,15);
floodfill(xf,yf,6);
}
void comp()
{
setcolor(0);
settextstyle(1,0,3);
outtextxy(275,390," Intake");
setcolor(5);
settextstyle(1,0,3);
outtextxy(255,390,"Compression");
int xf=xc;
int yf=yc-150;
setfillstyle(1,0);
floodfill(259,69,6);
for(int i=0;i<20;i++)
{
transpst(-3);
transshaft(-3);
}
setfillstyle(1,14);
floodfill(xf,yf,6);
}
void spark()
{
setcolor(0);
settextstyle(1,0,3);
outtextxy(255,390,"Compression");
setcolor(5);
settextstyle(1,0,3);
outtextxy(277,390,"Ignition");
setcolor(4);
line(xc,yc-166,xc-2,yc-160);
line(xc-6,yc-166,xc-10,yc-160);
line(xc+3,yc-166,xc+5,yc-160);
line(xc+9,yc-166,xc+13,yc-160);
}
void expa()
{
setcolor(0);
settextstyle(1,0,3);
outtextxy(277,390,"Ignition");
setcolor(5);
settextstyle(1,0,3);
outtextxy(270,390,"Expansion");
int xf=xc;
int yf=yc-150;
setfillstyle(1,0);
floodfill(xf,yf,6);
for(int i=0;i<20;i++)
{
transpst(3);
transshaft(3);
}
setfillstyle(1,15);
floodfill(xf,yf,6);
}
void exhaust()
{
setcolor(0);
settextstyle(1,0,3);
outtextxy(270,390,"Expansion");
setcolor(5);
settextstyle(1,0,3);
outtextxy(277,390,"Exhaust");
int xf=xc;
int yf=yc-150;
setfillstyle(1,0);
floodfill(xf,yf,6);
for(int i=0;i<20;i++)
{
transpst(-3);
transshaft(-3);
// transout(1);
}
transout(20);
transout(-20);
}
void draw()
{
cyllinder();
drawpst();
drawin();
drawout();
drawshaft();
}
void contd()
{
for(int i=0;i<2;i++)
{
intake();
delay(700);
comp();
delay(700);
spark();
delay(1000);
expa();
delay(700);
exhaust();
}
}
void back()
{
cleardevice();
init();
setbkcolor(3);
draw();
setcolor(15);
setlinestyle(0,0,3);
rectangle(5,5,633,475);
setcolor(1);
settextstyle(0,0,1);
outtextxy(150,430,"* Press ENTER to see engine strokes one by one *");
outtextxy(150,450,"* Press SPACE BAR to see continues engine cycle *");
outtextxy(382,360,"* Press 'N' for Nomenclature *");
setcolor(4);
rectangle(10,10,40,30);
outtextxy(14,16,"Esc");
outtextxy(45,16,"Press Escape to QUIT");
setcolor(11);
settextstyle(0,0,9);
outtextxy(35,310,"4");
setcolor(4);
settextstyle(0,0,3);
outtextxy(65,350,"Stroke");
setcolor(14);
settextstyle(1,0,6);
outtextxy(420,140,"Internal");
settextstyle(1,0,4);
outtextxy(425,230,"Combustion");
setcolor(11);
settextstyle(1,0,7);
outtextxy(545,90,"E");
settextstyle(1,0,6);
outtextxy(417,140," n");
settextstyle(1,0,5);
outtextxy(555,182,"g");
settextstyle(1,0,4);
outtextxy(433,230," i");
settextstyle(1,0,3);
outtextxy(559,258,"n");
settextstyle(1,0,2);
outtextxy(562,280,"e");
setcolor(15);
}
void name()
{
back();
setcolor(15);
settextstyle(2,0,6);
setlinestyle(0,0,1);
outtextxy(280,5,"Spark Plug");
outtextxy(170,25,"Intake Valve");
outtextxy(370,25,"Exhaust Valve");
line(250,120,300,120);
outtextxy(140,108,"Vccum Rings");
outtextxy(295,130,"Piston");
line(230,200,320,200);
outtextxy(135,188,"Piston Rod");
outtextxy(340,170,"Cyllinder");
line(200,250,320,250);
outtextxy(90,240,"Crank Shaft");
getch();
back();
}
void main()
{
initgraph(&gd,&gm,"C:/TC/bgi");
back();
char choice;
int count=0;
while(choice!=27)
{
choice=getch();
switch(choice)
{
case 'n':
case 'N':
name();
count=0;
break;
case 13:switch(count)
{
case 0:
intake();
count++;
break;
case 1:comp();
count++;
break;
case 2:spark();
count++;
break;
case 3:expa();
count++;
break;
case 4:exhaust();
count=0;
break;
}
break;
case 32:back();
contd();
count=0;
break;
}
}
cleardevice();
setbkcolor(9);
settextstyle(4,0,8);
setcolor(15);
setlinestyle(0,0,3);
rectangle(5,5,633,475);
setcolor(4);
outtextxy(50,100,"THANK YOU !!");
settextstyle(3,0,4);
outtextxy(200,250,"CREATED BY:-");
outtextxy(200,300,"VIVEK P. MEHTA");
outtextxy(200,350,"B.E. 3RD COMPUTER");
getch();
}
No comments:
Post a Comment