/***************************************************************************/
/* VIRTUAL DRILLING MACHINE */
/* */
/* CG Project */
/* By Sampathirao Muralidhar B */
/* C.K.Pithawala College of Engg. & Tech. */
/* B.E. Computer-III, 5th Sem (6144) */
/***************************************************************************/
#include iostream.h
#include conio.h
#include stdlib.h
#include graphics.h
#include dos.h
#include math.h
#define MAXX 639
#define MAXY 479
#define interval 90
#define w() {setcolor(WHITE);}
#define lg() {setcolor(LIGHTGRAY);}
#define y() {setcolor(YELLOW);}
#define lb() {setcolor(LIGHTBLUE);}
#define lc() {setcolor(YELLOW);} /* label color */
#define normal DARKGRAY
#define shine LIGHTGRAY
/*****************/
/* Global Var */
/*****************/
int ret=0;
static int no=0;
int on_off=-1; /* indicates status of m/c ON->(1) or OFF->(-1) */
int x_limit=0;
static int degree=0;
static int x_co_ord[5],y_co_ord[5];
int reset=0;
int c=7; /* hole color */
/*****************/
void init_arr(int *);
void y_trans();
void y_trans_1();
void y_control(int);
int z_trans(int);
void z_control(void);
void x_control(void);
void x_trans(int);
int table_trans(int);
void point_trans(int,int);
void tool_trans(int);
void operation(void);
void m_on_off(void);
void hole(void);
void s_hole(void);
void label(void);
class stack
{
private:
int poly[8];
int top;
public:
int convert;
stack(int x1,int y1,int x2,int y2)
{
top=-1;
convert=1;
push(x1);
push(y1);
push(x2);
push(y2);
}
void push(int co_ord)
{
if(top==7)
return;
top++;
poly[top]=co_ord;
}
int pop()
{
if(top==-1)
return NULL;
int temp=poly[top];
top--;
return temp;
}
}y_handle(280,312,295,314),
z_handle(260,132,275,135),
table_obj(175,275,205,295),
point_obj(355+30,150+25,0,0),
tool_obj(185,200,196,205);
void calc(int *,int,int,int,int);
void hori_pix(int,int,int,int,int,int,int);
void verti_pix(int,int,int,int,int,int,int);
void line_fill(int,int,int,int,int,int,int,int);
void pixelize(int,int,int,int,int,int,int);
void border(void);
void my_menu();
void menu_access_opt1(void);
void menu_access_opt2(void);
void menu_access_opt3(void);
void draw(void);
int direction(int);
void msg(int,int);
/****************************************************************************/
void my_menu()
{
int i,j;
setcolor(RED+GREEN);
pixelize(RED+GREEN,50,200,65,215,20,1);
outtextxy(70,207,"Parts of Drilling M/C");
pixelize(RED+GREEN,50,220,65,235,20,1);
outtextxy(70,227,"Start virtual drill");
pixelize(RED+GREEN,50,240,65,255,20,1);
outtextxy(70,247,"Exit");
setcolor(LIGHTGRAY);
outtextxy(10,MAXY-30,"\n Press 'm' to access the menu or enjoy the visuals");
again:
while(!kbhit())
{
verti_pix(250,150,350,RED+GREEN,YELLOW,2,10);
}
if(getch()==(int)'m')
{
outtextxy(10,MAXY-15,"\n Use Up & Down arrow key");
menu_access_opt1();
}
else
goto again;
}
/***************************************************************************/
void pixelize(int color,int x1,int y1,int x2,int y2,int delta,int gap)
{
int i,j;
for(i=y1+1;i<=y2-1;i+=gap)
{
for(j=x1+1;j<=x2-1;j+=gap)
{
putpixel(j,i,color);
}
delay(delta);
}
}
/***************************************************************************/
void in_graph()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\tc\\bgi");
}
/***************************************************************************/
my_window()
{
int i=0;
border();
pixelize(RED,3,3,MAXX-3,MAXY-3,0,2);
line_fill(RED,3,3,MAXX-3,MAXY-3,3,2,1);
while(i!=80)
{
setcolor(YELLOW);
line(i*8,4,MAXX-3,4+(i*8));
delay(20);
i=i+1;
}
i=0;
setcolor(YELLOW);
delay(interval);
outtextxy(getmaxx()/2-50,getmaxy()/2,"Welcome to Virtual Drilling");
hori_pix(getmaxx()/2-50,getmaxy()/2+10,getmaxx()/2-50+216,YELLOW,RED,2,10);
setcolor(RED+GREEN);
outtextxy(getmaxx()/2-50,getmaxy()/2+40+10,"CG Project");
delay(interval);
outtextxy(getmaxx()/2-50,getmaxy()/2+40+20,"By Sampathirao Muralidhar");
delay(interval);
outtextxy(getmaxx()/2-50,getmaxy()/2+40+30,"C.K.Pithawala College of Engg. & Tech.");
delay(interval);
outtextxy(getmaxx()/2-50,getmaxy()/2+40+40,"III-Computer (6144)");
delay(interval);
my_menu();
while(i!=80)
{
setcolor(RED);
line(i*8,4,MAXX-3,4+(i*8));
delay(20);
i=i+1;
}
border();
switch(ret)
{
case 1: line_fill(BLACK,3,3,MAXX-3,MAXY-3,3,1,1);
cleardevice();
setcolor(LIGHTBLUE);
outtextxy(240,15,"\n Parts of Drilling M/c");
draw();
label();
break;
case 2: line_fill(BLACK,3,3,MAXX-3,MAXY-3,3,1,1);
cleardevice();
setcolor(LIGHTBLUE);
outtextxy(100,15,"\n Drilling & Milling M/c ");
draw();
operation();
break;
case 3: pixelize(BLACK,3,3,MAXX-3,MAXY-3,0,2);
line_fill(BLACK,3,3,MAXX-3,MAXY-3,0,1,1);
lb();
outtextxy(140,120,"Impossible is not a fact, its an opinion!!");
outtextxy(245,140,"Thanks for visiting");
w();
outtextxy(350,240,"Pree any key to Exit");
getch();
exit(0);
break;
}
return 0;
}
/***************************************************************************/
void hori_pix(int x1,int y,int x2,int color,int dissolve_color,int gap,int wt_time)
{
int x_temp=x1;
while(x_temp<=x2)
{
putpixel(x_temp,y,color);
delay(wt_time);
x_temp+=gap;
}
x_temp=x1;
while(x_temp<=x2)
{
putpixel(x_temp,y,dissolve_color);
delay(wt_time);
x_temp+=gap;
}
}
/***************************************************************************/
void verti_pix(int x,int y1,int y2,int color,int dissolve_color,int gap,int wt_time)
{
int y_temp=y1;
while(y_temp<=y2)
{
putpixel(x,y_temp,color);
delay(wt_time);
y_temp+=gap;
}
y_temp=y1;
while(y_temp<=y2)
{
putpixel(x,y_temp,dissolve_color);
delay(wt_time);
y_temp+=gap;
}
}
/**************************************************************************/
void border()
{
setcolor(WHITE);
rectangle(0,0,MAXX,MAXY);
rectangle(2,2,MAXX-2,MAXY-2);
}
/**************************************************************************/
void menu_access_opt1()
{
int ch;
setcolor(RED+GREEN);
pixelize(RED+GREEN,50,220,65,235,0,1);
outtextxy(70,227,"Start virtual drill");
pixelize(RED+GREEN,50,240,65,255,0,1);
outtextxy(70,247,"Exit");
while(!kbhit())
{
pixelize(YELLOW,50,200,65,215,0,1);
setcolor(YELLOW);
outtextxy(70,207,"Parts of Drilling M/C");
}
ch=getch();
if(ch==13)
ret=1;
else if(ch==80)
{
menu_access_opt2();
}
else if(ch==72)
{
menu_access_opt3();
}
else
menu_access_opt1();
}
/**************************************************************************/
void menu_access_opt2()
{
int ch;
setcolor(RED+GREEN);
pixelize(RED+GREEN,50,200,65,215,0,1);
outtextxy(70,207,"Parts of Drilling M/C");
pixelize(RED+GREEN,50,240,65,255,0,1);
outtextxy(70,247,"Exit");
while(!kbhit())
{
pixelize(YELLOW,50,220,65,235,0,1);
setcolor(YELLOW);
outtextxy(70,227,"Start virtual drill");
}
ch=getch();
if(ch==13)
ret=2;
else if(ch==80)
{
menu_access_opt3();
}
else if(ch==72)
{
menu_access_opt1();
}
else
menu_access_opt2();
}
/**************************************************************************/
void menu_access_opt3()
{
int ch;
setcolor(RED+GREEN);
pixelize(RED+GREEN,50,200,65,215,0,1);
outtextxy(70,207,"Parts of Drilling M/C");
pixelize(RED+GREEN,50,220,65,235,0,1);
outtextxy(70,227,"Start virtual drill");
while(!kbhit())
{
pixelize(YELLOW,50,240,65,255,0,1);
setcolor(YELLOW);
outtextxy(70,247,"Exit");
}
ch=getch();
if(ch==13)
ret=3;
else if(ch==80)
{
menu_access_opt1();
}
else if(ch==72)
{
menu_access_opt2();
}
else
menu_access_opt3();
}
/**************************************************************************/
void line_fill(int color,int x1,int y1,int x2,int y2,int wt_time,int type,int gap)
{
int i;
switch(type)
{
case 1: for(i=x1+1;i
setcolor(color);
line(i,y1+1,i,y2-1);
delay(wt_time);
}
break;
case 2: for(i=y2-1;i>y1;i-=gap)
{
setcolor(color);
line(x1+1,i,x2-1,i);
delay(wt_time);
}
break;
}
}
/**************************************************************************/
void draw()
{
int arr[8];
border();
hori_pix(205,275,355,GREEN,DARKGRAY,2,10); /* OBJECT VIEWS */
hori_pix(205,295,355,GREEN,DARKGRAY,2,10);
verti_pix(355,150,275,GREEN,DARKGRAY,2,10);
verti_pix(415,150,275,GREEN,DARKGRAY,2,10);
setcolor(WHITE);
rectangle(355,275,415,295); /* Side view */
rectangle(355,150,415,200); /* Top view*/
putpixel(355+30,150+25,YELLOW);
hori_pix(375,175,395,BLUE,LIGHTBLUE,4,10);
verti_pix(385,165,186,BLUE,LIGHTBLUE,4,10);
setcolor(LIGHTBLUE);
outtextxy(160,200,"O");
outtextxy(160,210,"m");
outtextxy(160,220," ");
outtextxy(160,230,"S");
outtextxy(160,240,"a");
outtextxy(160,250,"i");
setcolor(WHITE); /* BODY */
rectangle(155,170,225,290);
rectangle(153,168,227,290);
w();
rectangle(180,50,200,90); /* MOTOR */
line(180,45,180,50);
line(200,45,200,50);
arc(185,45,90,180,5);
arc(195,45,0,90,5);
line(185,40,195,40);
rectangle(175,75,180,90);
rectangle(200,65,210,90);
pixelize(normal,200,65,210,90,0,1);
line_fill(WHITE,180,50,200,90,0,1,2);
rectangle(165,90,216,175); /* Head */
line_fill(LIGHTBLUE,165,90,216,175,0,2,2);
setcolor(WHITE);
outtextxy(167,96,"Ka9L13");
rectangle(180,125,200,165);
rectangle(190,130,190,160);
rectangle(185,130,195,132);
line_fill(WHITE,185,130,195,132,0,1,1);
rectangle(130,90,165,120); /* ON/OFF Board */
pixelize(LIGHTBLUE,130,90,165,120,0,2);
w();
rectangle(135,110,140,115);
line_fill(LIGHTGRAY,135,110,140,115,0,1,1);
line_fill(LIGHTGREEN,155,110,160,115,0,1,1);
setcolor(WHITE);
rectangle(155,110,160,115);
circle(148,100,5);
line(148,100,148,95);
rectangle(216,130,235,160); /* Feed Lever */
line_fill(LIGHTBLUE,216,130,235,160,0,2,3);
line_fill(LIGHTBLUE,216,130,235,160,0,1,3);
line_fill(normal,235,140-3,245,150+3,0,1,1);
line_fill(WHITE,235,140,245,143,0,1,1);
w();
rectangle(235,140-3,245,150+3);
rectangle(245,130+4,250,160-4);
line(250,134,255,130);
line(250,156,255,160);
rectangle(255,130,260,160);
rectangle(260,132,275,135); /*handle*/
line_fill(BROWN,170,175,211,180,0,1,2);
line_fill(BROWN,167,190,213,195,0,1,2 );
setfillstyle(1,BROWN);
fillellipse(180,185,5,5);
fillellipse(201,185,5,5);
line_fill(BROWN,180,180,201,190,0,1,1);
w();
rectangle(170,175,211,180); /* chuck */
arc(180,185,90,270,5);
arc(201,185,270,90,5);
rectangle(167,190,213,195);
rectangle(180,195,201,200);
rectangle(185,200,196,205); /*small*/
line_fill(normal,185,200,192,205,0,1,1);
line_fill(shine,191,200,194,205,0,1,1);
line_fill(normal,193,200,196,205,0,1,1);
w();
rectangle(180,205,201,209);
line(184,225,197,225);
ellipse(184,205,180,270,4,20);
ellipse(197,205,270,360,4,20);
ellipse(193,211,270,360,4,13);
ellipse(192,211,270,360,4,14);
rectangle(186,227,195,234);
line_fill(normal,186,227,195,234,0,1,1);
line_fill(shine,191,227,194,234,0,1,1);
w();
rectangle(189,234,192,255); /*tool*/
calc(arr,189,234,192,255);
setfillstyle(4,WHITE);
fillpoly(4,arr);
line(189,255,190,258);
line(190,258,192,255);
rectangle(120,295,260,310); /* TABLE */
rectangle(135,290,245,295);
rectangle(175,275,205,295); /*object*/
setfillstyle(9,BROWN);
calc(arr,175,275,205,295);
fillpoly(4,arr);
rectangle(137,288,140,290); /*l-nut*/
line_fill(WHITE,137,288,140,290,0,1,1);
rectangle(240,288,243,290); /*r-nut*/
line_fill(WHITE,240,288,243,290,0,1,1);
rectangle(170,280,175,290); /*l-support*/
rectangle(168,282,170,286);
line_fill(WHITE,168,283,170,285,0,1,1);
rectangle(205,280,210,290); /*r-support*/
rectangle(210,282,212,286);
line_fill(WHITE,210,283,212,285,0,1,1);
line_fill(shine,245,313,265,325,0,2,1);
line_fill(normal,245,315,265,318,0,2,1);
line(245,320,265,320);
line_fill(WHITE,265,317,270,319,0,1,1);
w();
rectangle(245,313,265,325); /* y-Trans-r */
rectangle(265,315,270,323);
rectangle(270,313,273,325);
line(273,313,276,310);
line(273,325,276,328);
rectangle(276,310,280,328);
rectangle(280,312,295,314); /*handle*/
/****************************************/
/* x-Trans-color */
/****************************************/
line_fill(normal,135,312,245,332,0,1,1);
setfillstyle(1,normal);
arr[0]=135;
arr[1]=332;
arr[2]=155;
arr[3]=332;
arr[4]=165;
arr[5]=342;
arr[6]=155;
arr[7]=342;
fillpoly(4,arr);
arr[0]=245;
arr[2]=225;
arr[4]=215;
arr[6]=225;
fillpoly(4,arr);
w();
/****************************************/
line(135,312,245,312); //1 /* x-TRANS-r */
line(135,312,135,332); //2
line(245,312,245,332); //3
line(135,332,155,342); //4
line(155,342,165,342); //5
line(165,342,155,332); //6
line(245,332,225,342); //7
line(225,342,215,342); //8
line(215,342,225,332); //9
line(155,332,225,332); //10
line(160,334,220,334); //11
line(160,334,170,344); //12
line(220,334,210,344); //13
line(170,344,135,344); //14
line(210,344,245,344); //15
line(135,344,135,380); //16
line(245,344,245,380); //17
line(135,380,245,380); //18
/**********************/
/* x_handle back fill */
/**********************/
line_fill(BROWN,135,344,245,380,0,2,1);
setfillstyle(1,BROWN);
arr[0]=163;
arr[1]=335;
arr[2]=218;
arr[3]=335;
arr[4]=207;
arr[5]=346;
arr[6]=173;
arr[7]=346;
fillpoly(4,arr);
w();
/**********************/
circle(190,362,10);
circle(190,357,2);
setfillstyle(1,RED);
fillellipse(190,362,10,10);
setfillstyle(1,LIGHTRED); //x_handle
fillellipse(190,357,2,2);
putpixel(190,362,YELLOW);
rectangle(80,380,135,420); //1 /* BASE */
rectangle(245,380,300,420); //2
rectangle(135,380,245,400); //3
line_fill(BROWN,134,380,246,400,0,1,2); //3
line_fill(BROWN,246,380,300,420,0,1,2); //2
line_fill(BROWN,80,380,135,420,0,1,2); //1
line_fill(normal,120,295,260,310,0,2,2); //table fill
}
/**************************************************************************/
void calc(int *p,int x1,int y1,int x2,int y2)
{
*(p)=x1;
*(p+1)=y1;
*(p+2)=x2;
*(p+3)=y1;
*(p+4)=x2;
*(p+5)=y2;
*(p+6)=x1;
*(p+7)=y2;
}
/**************************************************************************/
void y_trans()
{
int x1,y1,x2,y2,k1=0,i=-1;
setcolor(BLACK);
y2=y_handle.pop();
x2=y_handle.pop();
y1=y_handle.pop();
x1=y_handle.pop();
if (y1<=312)
{
k1=direction(3);
}
else if(y1>=324)
{
k1=direction(4);
}
i=i*(y_handle.convert);
rectangle(x1,y1,x2,y2);
setcolor(WHITE);
rectangle(276,310,280,328);
rectangle(x1,y1+i,x2+k1,y2+i);
y_handle.push(x1);
y_handle.push(y1+i);
y_handle.push(x2+k1);
y_handle.push(y2+i);
if(degree==-12)
{
if(table_trans(-2))
{
msg(4,10);
y_control(1);
}
else msg(2,0);
degree=0;
}
degree--;
}
/***************************************************************************/
void y_trans_1()
{
int x1,y1,x2,y2,k1=0,i=1;
setcolor(BLACK);
y2=y_handle.pop();
x2=y_handle.pop();
y1=y_handle.pop();
x1=y_handle.pop();
if (y1<=312)
{
k1=direction(1);
}
else if(y1>=324)
{
k1=direction(2);
}
i=i*(y_handle.convert);
rectangle(x1,y1,x2,y2);
setcolor(WHITE);
rectangle(276,310,280,328);
rectangle(x1,y1+i,x2+k1,y2+i);
y_handle.push(x1);
y_handle.push(y1+i);
y_handle.push(x2+k1);
y_handle.push(y2+i);
if(degree==12)
{
if(table_trans(2))
{
msg(4,10);
y_control(2);
}
else msg(2,0);
degree=0;
}
degree++;
}
/***************************************************************************/
int direction(int x)
{
static int k=0;
if(x==1 && k==0)
return 0;
if(x==3 && k==1)
return 0;
if(x==4 && k==0)
return 0;
if(x==2 && k==1)
return 0;
if(k==1) //1 for back
{
k=0;
y_handle.convert=y_handle.convert*(-1);
return 1;
}
else
{
k=1;
y_handle.convert=y_handle.convert*(-1);
return -1;
}
}
/***************************************************************************/
void y_control(int limit)
{
int ch;
while(!kbhit()){}
ch=getch();
if(ch==72 && limit!=1)
{
y_trans();
y_control(0);
}
else if(ch==80 && limit!=2)
{
y_trans_1();
y_control(0);
}
else if(ch==27)
operation();
else
y_control(limit);
}
/***************************************************************************/
int z_trans(int z_vector)
{
int x1,y1,x2,y2;
y2=z_handle.pop();
x2=z_handle.pop();
y1=z_handle.pop();
x1=z_handle.pop();
if(y2+z_vector<=134 || y2+z_vector>=154)
{
msg(5,0);
z_handle.push(x1);
z_handle.push(y1);
z_handle.push(x2);
z_handle.push(y2);
return 1;
}
if(y1+z_vector>=141 && on_off==-1)
{
msg(6,0);
z_handle.push(x1);
z_handle.push(y1);
z_handle.push(x2);
z_handle.push(y2);
return 1;
}
else
{
msg(2,0);
setcolor(BLACK);
rectangle(x1,y1,x2,y2);
w();
rectangle(255,130,260,160);
rectangle(x1,y1+z_vector,x2,y2+z_vector);
tool_trans(z_vector*2);
if(y1>=141)
s_hole();
z_handle.push(x1);
z_handle.push(y1+z_vector);
z_handle.push(x2);
z_handle.push(y2+z_vector);
setcolor(BLACK);
rectangle(355,273,415,274);
}
return 0;
}
/***************************************************************************/
int table_trans(int x_vector)
{
int x1,y1,x2,y2,arr[8];
setcolor(BLACK);
y2=table_obj.pop();
x2=table_obj.pop();
y1=table_obj.pop();
x1=table_obj.pop();
if(x1+x_vector<=164 || x2+x_vector>=216)
{
table_obj.push(x1);
table_obj.push(y1);
table_obj.push(x2);
table_obj.push(y2);
return 1;
}
rectangle(x1-55,295,x2+55,310); /*Table*/
line_fill(BLACK,x1-55,295,x2+55,310,0,1,1);
rectangle(x1-40,290,x2+40,295);
rectangle(x1-38,288,x2-65,290); /*l-nut*/
line_fill(BLACK,x1-38,288,x2-65,290,0,1,1);
rectangle(x1+65,288,x2+38,290); /*r-nut*/
line_fill(BLACK,x1+65,288,x2+38,290,0,1,1);
rectangle(x1-5,280,x2-30,290); /*l-support*/
rectangle(x1-7,282,x2-35,286);
line_fill(BLACK,x1-7,282,x2-35,286,0,1,1);
rectangle(x1+30,280,x2+5,290); /*r-support*/
rectangle(x1+35,282,x2+7,286);
line_fill(BLACK,x1+35,282,x2+7,286,0,1,1);
setfillstyle(9,BLACK);
calc(arr,x1,y1,x2,y2);
fillpoly(4,arr);
rectangle(x1,y1,x2,y2); /*object*/
table_obj.push(x1+x_vector);
table_obj.push(y1);
table_obj.push(x2+x_vector);
table_obj.push(y2);
/********************************************/
/* REDRAW CODE */
/********************************************/
x1=x1+x_vector;
x2=x2+x_vector;
point_trans(0,-x_vector*2);
setcolor(WHITE);
rectangle(x1-55,295,x2+55,310); /*Table*/
line_fill(normal,x1-55,295,x2+55,310,0,2,2);
w();
rectangle(x1-40,290,x2+40,295);
rectangle(x1-38,288,x2-65,290); /*l-nut*/
line_fill(WHITE,x1-38,288,x2-65,290,0,1,1);
rectangle(x1+65,288,x2+38,290); /*r-nut*/
line_fill(WHITE,x1+65,288,x2+38,290,0,1,1);
rectangle(x1-5,280,x2-30,290); /*l-support*/
rectangle(x1-7,282,x2-35,286);
line_fill(WHITE,x1-7,283,x2-35,285,0,1,1);
rectangle(x1+30,280,x2+5,290); /*r-support*/
rectangle(x1+35,282,x2+7,286);
line_fill(WHITE,x1+35,283,x2+7,285,0,1,1);
setfillstyle(9,BROWN);
calc(arr,x1,y1,x2,y2);
fillpoly(4,arr);
rectangle(x1,y1,x2,y2); /*object*/
return 0;
}
/***************************************************************************/
void point_trans(int x_vector,int y_vector)
{
int x1,y1;
y1=point_obj.pop();
x1=point_obj.pop();
if (x1+x_vector<358)
{
point_obj.push(x1);
point_obj.push(y1);
x_limit=1;
}
else if(x1+x_vector>412)
{
point_obj.push(x1);
point_obj.push(y1);
x_limit=2;
}
else
{
putpixel(x1,y1,BLACK);
hori_pix(x1-10,y1,x1+10,BLACK,BLACK,4,0);
verti_pix(x1,y1-10,y1+11,BLACK,BLACK,4,0);
point_obj.push(x1+x_vector);
point_obj.push(y1+y_vector);
/*****************/
/* REDRAW */
/*****************/
w();
rectangle(355,150,415,200);
x1=x1+x_vector;
y1=y1+y_vector;
putpixel(x1,y1,YELLOW);
hori_pix(x1-10,y1,x1+10,BLUE,LIGHTBLUE,4,0);
verti_pix(x1,y1-10,y1+11,BLUE,LIGHTBLUE,4,0);
x_limit=0;
}
}
/***************************************************************************/
void operation()
{
int ch;
line_fill(BLACK,499,34,635,43,0,2,1);
reset=0;
c=7;
msg(0,20);
lb();
outtextxy(500,15,"Press:");
w();
if(on_off==-1)
outtextxy(500,35,"s:Start M/c");
else
outtextxy(500,35,"s:Stop M/c");
outtextxy(500,50,"x:x-Translation");
outtextxy(500,65,"y:y-Translation");
outtextxy(500,80,"f:Feed tool");
outtextxy(500,95,"h:Homepage");
setcolor(LIGHTRED);
outtextxy(500,110,"Esc:To abort the");
outtextxy(500,126," operation");
again:
while(!kbhit())
{
line(548,22 ,554,22);
}
ch=getch();
switch(ch)
{
case 115:lb();
if(on_off==-1)
outtextxy(500,35,"s:Start M/c");
else
outtextxy(500,35,"s:Stop M/c");
w();
outtextxy(500,15,"Press:");
m_on_off();
break;
case 120:msg(2,20);
lb();
outtextxy(500,50,"x:x-Translation");
w();
outtextxy(500,15,"Press:");
x_control();
break;
case 121:msg(2,20);
lb();
outtextxy(500,65,"y:y-Translation");
w();
outtextxy(500,15,"Press:");
y_control(0);
break;
case 102:msg(2,10);
lb();
outtextxy(500,80,"f:Feed tool");
w();
outtextxy(500,15,"Press:");
z_control();
break;
case 104:y();
my_window();
break;
default :goto again;
}
}
/***************************************************************************/
void msg(int no,int delay)
{
int ch;
y();
outtextxy(440,445,"Message:");
line_fill(BLACK,439,463,633,474,delay,2,1);
y();
switch(no)
{
case 0: outtextxy(440,465,"Select the operation");
break;
case 1: if(on_off==1)
outtextxy(440,465,"Press Enter to STOP M/c");
else
outtextxy(440,465,"Press Enter to START M/c");
break;
case 2: outtextxy(440,465,"Use up & down arrows");
break;
case 3: outtextxy(440,465,"X-Limit reached");
break;
case 4: outtextxy(440,465,"Y-Limit reached");
break;
case 5: outtextxy(440,465,"Z-Limit reached");
break;
case 6: outtextxy(440,465,"Can't drill, M/c is OFF");
break;
case 7: while(!kbhit())
outtextxy(440,465,"Max holes, Esc twice");
if(getch()==27)
break;
else msg(7,0);
}
}
/***************************************************************************/
void m_on_off()
{
int ch,arr[8];
calc(arr,189,234,192,255);
msg(1,20);
while(!kbhit()){}
ch=getch();
if(ch==13 && on_off==-1)
{
on_off=on_off*(-1);
line_fill(RED,135,110,140,115,0,1,1);
operation();
}
else if(ch==13 && on_off==1)
{
on_off=on_off*(-1);
line_fill(LIGHTGRAY,135,110,140,115,0,1,1);
operation();
}
else if(ch==27)
operation();
else m_on_off();
}
/***************************************************************************/
void z_control()
{
int ch;
while(!kbhit()){}
ch=getch();
if(ch==72)
{
z_trans(-1);
z_control();
}
else if(ch==80)
{
z_trans(1);
z_control();
}
else if(ch==27)
{
while(!z_trans(-1)){}
operation();
}
else
z_control();
}
/***************************************************************************/
void tool_trans(int z_vector)
{
int x1,y1,x2,y2,arr[8],y2_temp;
y2=tool_obj.pop();
x2=tool_obj.pop();
y1=tool_obj.pop();
x1=tool_obj.pop();
y2_temp=y2;
setcolor(BLACK);
rectangle(x1,y1,x2,y2);
line_fill(BLACK,x1,y1,x2-4,y2,0,1,1);
line_fill(BLACK,x2-5,y1,x2-2,y2,0,1,1);
line_fill(BLACK,x2-3,y1,x2,y2,0,1,1);
rectangle(180,y2,201,y2+4);
line(184,y2+20,197,y2+20);
ellipse(184,y2,180,270,4,20);
ellipse(197,y2,270,360,4,20);
ellipse(193,y2+6,270,360,4,13); /*chuck shine */
ellipse(192,y2+6,270,360,4,14);
rectangle(186,y2+22,195,y2+29); /*small*/
rectangle(189,y2+29,192,y2+50); /*tool*/
calc(arr,189,y2+29,192,y2+50);
line_fill(BLACK,186,y2+22,195,y2+29,0,1,1); /*tool holder*/
line_fill(BLACK,191,y2+22,194,y2+29,0,1,1);
setfillstyle(4,BLACK);
fillpoly(4,arr);
line(189,y2+50,190,y2+53);
line(190,y2+53,192,y2+50);
tool_obj.push(x1);
tool_obj.push(y1);
tool_obj.push(x2);
tool_obj.push(y2+z_vector);
/*********************************/
/* REDRAW */
/*********************************/
y2=y2+z_vector;
w();
rectangle(x1,y1,x2,y2);
line_fill(normal,x1,y1,x2-4,y2,0,1,1);
line_fill(shine,x2-5,y1,x2-2,y2,0,1,1);
line_fill(normal,x2-3,y1,x2,y2,0,1,1);
w();
rectangle(180,y2,201,y2+4);
line(184,y2+20,197,y2+20);
ellipse(184,y2,180,270,4,20);
ellipse(197,y2,270,360,4,20);
ellipse(193,y2+6,270,360,4,13); /*chuck shine */
ellipse(192,y2+6,270,360,4,14);
rectangle(186,y2+22,195,y2+29); /*small*/
rectangle(189,y2+29,192,y2+50); /*tool*/
line_fill(normal,186,y2+22,195,y2+29,0,1,1); /*tool holder*/
line_fill(shine,191,y2+22,194,y2+29,0,1,1);
w();
calc(arr,189,y2+29,192,y2+50);
setfillstyle(4,WHITE);
fillpoly(4,arr);
line(189,y2+50,190,y2+53);
line(190,y2+53,192,y2+50);
y2=table_obj.pop(); /*update object*/
x2=table_obj.pop();
y1=table_obj.pop();
x1=table_obj.pop();
setfillstyle(9,BROWN);
calc(arr,x1,y1,x2,y2);
fillpoly(4,arr);
rectangle(x1,y1,x2,y2);
table_obj.push(x1);
table_obj.push(y1);
table_obj.push(x2);
table_obj.push(y2);
if(no>4)
{
no=0;
msg(7,10);
init_arr(x_co_ord);
init_arr(y_co_ord);
reset=1;
c=0;
line_fill(BLACK,355,150,415,200,10,1,1);
line_fill(BLACK,355,275,415,295,10,2,1);
point_trans(0,0);
w();
}
else if(y2_temp+53==276 && !reset)
{
hole();
}
}
/***************************************************************************/
void x_control()
{
int ch;
while(!kbhit()){}
ch=getch();
if(ch==72 && x_limit!=2)
{
x_trans(1);
x_control();
}
else if(ch==80 && x_limit!=1)
{
x_trans(-1);
x_control();
}
else if(ch==27)
{
operation();
}
else
x_control();
}
/***************************************************************************/
void x_trans(int rot_vector)
{
static double x1=190,y1=357;
static int x_degree=0;
double x_temp,y_temp;
int k;
x_degree=x_degree+rot_vector;
setcolor(BLACK);
circle(190,362,10);
circle(x1,y1,2); //x_handle
/********************************/
/* REDRAW */
/********************************/
x_temp=190+(x1-190)*cos(rot_vector)-(y1-362)*sin(rot_vector);
y_temp=362+(x1-190)*sin(rot_vector)+(y1-362)*cos(rot_vector);
x1=x_temp;
y1=y_temp;
w();
circle(190,362,10);
setfillstyle(1,RED);
fillellipse(190,362,10,10);
circle(x1,y1,2); //x_handle
setfillstyle(1,LIGHTRED);
fillellipse(x1,y1,2,2);
putpixel(190,362,YELLOW);
if(x_degree<=12||x_degree>=-12)
{
x_degree=0;
point_trans(rot_vector*2,0);
if(x_limit)
msg(3,0);
else
msg(2,0);
}
}
/***************************************************************************/
void hole()
{
int x1,y1,j,pt=0;
y1=point_obj.pop();
x1=point_obj.pop();
point_obj.push(x1); /* reload point co_ord's */
point_obj.push(y1);
for(j=0;j<=no;j++)
{
if(x_co_ord[j]==x1 && y_co_ord[j]==y1)
{
pt=1;
break;
}
}
if(!pt)
{
x_co_ord[no]=x1;
y_co_ord[no]=y1;
no+=1;
for(j=0;j<=no;j++)
{
setfillstyle(1,LIGHTRED);
fillellipse(x_co_ord[j],y_co_ord[j],2,2);
}
}
}
/***************************************************************************/
void init_arr(int *p)
{
int i;
for(i=0;i<=4;i++)
{
*(p+i)=0;
}
}
/***************************************************************************/
void s_hole()
{
int pt_x1,pt_y1,tip;
pt_y1=point_obj.pop();
pt_x1=point_obj.pop();
point_obj.push(pt_x1); /* reload point co-ord's */
point_obj.push(pt_y1);
tip=tool_obj.pop()+53;
tool_obj.push(tip-53); /* reload tool tip */
line_fill(c,pt_x1-1,275,pt_x1+1,tip,0,1,1);
rectangle(pt_x1-1,275,pt_x1+1,tip);
w();
rectangle(355,275,415,295);
}
/***************************************************************************/
void label()
{
int k=20,ch;
hori_pix(204,55,250,shine,YELLOW,2,k);
lc();
outtextxy(254,50,"\n Motor");
hori_pix(220,95,270,shine,YELLOW,2,k);
lc();
outtextxy(274,90,"\n Head");
hori_pix(76,95,126,shine,YELLOW,2,k);
lc();
outtextxy(10,85,"\n On/Off");
outtextxy(10,95," Board");
hori_pix(278,135,325,shine,YELLOW,2,k);
lc();
outtextxy(329,130,"\n Feed Lever");
hori_pix(99,188,149,shine,YELLOW,2,k);
lc();
outtextxy(44,183,"\n Body");
hori_pix(199,215,249,shine,YELLOW,2,k);
lc();
outtextxy(253,210,"\n Chuck");
hori_pix(194,240,249,shine,YELLOW,2,k);
lc();
outtextxy(253,235,"\n Tool");
hori_pix(85,300,116,shine,YELLOW,2,k);
lc();
outtextxy(10,295,"\n Table");
outtextxy(10,305," & ");
outtextxy(10,315," Object");
hori_pix(204,360,254,shine,YELLOW,2,k);
lc();
outtextxy(258,355,"\n x-Translator");
hori_pix(299,310,349,shine,YELLOW,2,k);
lc();
outtextxy(352,305,"\n y-Translator");
hori_pix(300,385,368,shine,YELLOW,2,k);
lc();
outtextxy(372,380,"\n Base");
hori_pix(420,190,470,shine,YELLOW,2,k);
lc();
outtextxy(474,185,"\n Top view");
hori_pix(420,290,470,shine,YELLOW,2,k);
lc();
outtextxy(474,285,"\n Side view");
lb();
outtextxy(500,15,"Press:");
outtextxy(500,35,"h:Homepage");
while(getch()!=104){}
my_window();
}
/***************************************************************************/
void main()
{
in_graph();
setcolor(LIGHTBLUE);
settextstyle(0,0,1);
outtextxy(10,10,"Om Sai Ram");
settextstyle(0,0,1);
border();
outtextxy(350,240,"Pree any key to START");
getch();
cleardevice();
point_obj.pop(); //flush the unwanted
point_obj.pop();
my_window();
getch();
}
/***************************************************************************/
2 comments:
Thanx for posting my project.
Blog--------mast hai, jhakkas!!!!
Gr8.
Thanks.......
Post a Comment