#include <graphics.h> // 引用图形库头文件
#include <conio.h>
#include <stdio.h>
#include <windows.h> //用到了定时函数sleep()
#include <math.h>
#include <string.h>
#include <fstream>
#include <sstream>
#define PI 3.1416
int r[9][4]={{0,20,130,60},{130,20,260,60},{260,20,390,60},{390,20,520,60},{520,20,650,60},{650,20,780,60},{780,20,870,60},{870,20,960,60},{960,20,1050,60}};//三个按钮的二维数组
float d1,n1,n2,P1,Pz,vf,Bd,H,q,GA=1,f=0.36,vc,kif=0.97,T=6.21,kv=0.75,dz,hs,p1=3.14;
//根据插值法知道轴向力为2000N f为进给量,kif为修正系数,hs为加工孔长度
//v为切削速度17m/min,扭矩定义为T,钻头直径取6.5mm
//kv为切削系数 dz为钻头直径
//a=496,b=172,L1=40,L2=15,L3=32,B1=40,H1=32,hh=2.6,//动力箱
//j=400,k=100,H5=32.5,H6=200,N3=97,N4=66,B2=60,B3=11,H7=56,H8=21,H9=16,N5=71,N6=90,N=19,//立柱侧底座
//m=466,n=160,B=32,L=40,H2=107,H3=63,H4=15.5,N1=28,N2=22;//滑台 有些与动力箱的表达一样但是值不一样(H1)
//按钮判断函数
int button_judge(int x,int y)
{
if(x>r[0][0] && x<r[0][2] && y>r[0][1] && y<r[0][3])return 1;
if(x>r[1][0] && x<r[1][2] && y>r[1][1] && y<r[1][3])return 2;
if(x>r[2][0] && x<r[2][2] && y>r[2][1] && y<r[2][3])return 3;
if(x>r[3][0] && x<r[3][2] && y>r[3][1] && y<r[3][3])return 4;
if(x>r[4][0] && x<r[4][2] && y>r[4][1] && y<r[4][3])return 5;
if(x>r[5][0] && x<r[5][2] && y>r[5][1] && y<r[5][3])return 6;
if(x>r[6][0] && x<r[6][2] && y>r[6][1] && y<r[6][3])return 7;
if(x>r[7][0] && x<r[7][2] && y>r[7][1] && y<r[7][3])return 8;
if(x>r[8][0] && x<r[8][2] && y>r[8][1] && y<r[8][3])return 9;
return 0;
}
//初始化图像
void init_figure()
{
int i;
setrop2(R2_COPYPEN);//当前颜色
setlinecolor(BLACK);
setlinestyle(PS_SOLID);//实线
//外框线
//点线
//水平辅助线
}
void writehuatai()
{
float m=466,n=160,B=32,L=40,H2=107,H3=63,H4=15.5,N1=28,N2=22;
char chy[4]={ 'H' ,'a' ,'h','w' } ;
int data[4]={ 1 , 2 , 6 ,9 };
int i ;
FILE *fp = NULL ;
fp = fopen("D:\\cwenjian\\huatai.txt","w") ;
for (i=0 ; i<4 ;i++)
fprintf(fp,"%c=%d\n",chy[i],data[i] ) ;
fprintf(fp,"m=%f\n n=%f\n B=%f\n L=%f\n H2=%f\n H3=%f\n H4=%f\n N1=%f\n N2=%f\n",m,n,B,L,H2,H3,H4,N1,N2);
fclose(fp);
}
/*void writedonglixiang()
{
float a,b,L1,L2,L3,B1,H1,hh;
d1=hs/dz,vc=17,dz=6.5,hs=32;
vf=kv*vc;
n1=1000*vf/(p1*dz);
n2=n1/9550;
P1=T*n2;
Pz=4*P1;
if(Pz>=1 && Pz<=1.5)
{a=196,b=100,L1=32,L2=15,L3=32,B1=32,H1=25,hh=2.6;}//25
if(Pz>=1.5&&Pz<=3)
{a=496,b=172,L1=40,L2=15,L3=32,B1=40,H1=32,hh=2.6;}//32
FILE *fp = NULL ;
fp = fopen("D:\\cwenjian\\donglixiang.txt","w") ;
fprintf(fp,"a=%f\n b=%f\n L1=%f\n L2=%f\n L3=%f\n B1=%f\n H1=%f\n hh=%f\n",a,b,L1,L2,L3,B1,H1,hh);
fclose(fp);
}*/
void writelizhu()
{
float j,k,B1,H5,H6,N3,N4,B2,B3,H7,H8,H9,H1,N5,N6,N;
j=400,k=100,B1=40,H5=32.5,H6=200,N3=97,N4=66,B2=60,B3=11,H7=56,H8=21,H9=16,H1=6.5,N5=71,N6=90,N=19;
FILE *fp = NULL ;
fp = fopen("D:\\cwenjian\\lizhu.txt","w") ;
fprintf(fp,"j=%f\n k=%f\n B1=%f\n H5=%f\n H6=%f\n N3=%f\n N4=%f\n B2=%f\n B3=%f\n H7=%f\n H8=%f\n H9=%f\n H1=%f\n N5=%f\n N6=%f\n N=%f\n",j,k,B1,H5,H6,N3,N4,B2,B3,H7,H8,H9,H1,N5,N6,N);
fclose(fp);
}
void writeduozhouxiang()
{
float w,e,B,H,A0,A,h0,h,L0,L,B1,H1,GA;
w=850,e=400,B=50,H=50,A0=7.5,A=35,h0=15,h=20,L0=8,L=8,B1=40,H1=32,GA=0.1;
FILE *fp = NULL ;
fp = fopen("D:\\cwenjian\\duozhouxiang.txt","w") ;
fprintf(fp,"w=%f\n e=%f\n B=%f\n H=%f\n A0=%f\n A=%f\n h0=%f\n h=%f\n L0=%f\n L=%f\n B1=%f\n H1=%f\n GA=%f\n",w,e,B,H,A0,A,h0,h,L0,L,B1,H1,GA);
fclose(fp);
}
//仿真运行
int simulation()//动力箱
{
d1=hs/dz;//vc=17,dz=6.5,hs=32
vf=kv*vc;
n1=1000*vf/(p1*dz);
n2=n1/9550;
P1=T*n2;
Pz=4*P1;
// 打开文件
std::ifstream file("D://cwenjian//donglixiang2.txt");
// 读取文件中的数据
int a,b,L1,L2,L3,B1,H1,hh,GA;
char eq1, eq2, comma;
std::string line;
std::getline(file, line);
std::stringstream ss(line);
ss >> eq1 >> eq2 >> a >> comma >> eq1 >> eq2 >> b >>comma >> eq1 >> eq2 >>L1>> comma >> eq1 >> eq2 >>L2>>comma >> eq1 >> eq2 >>L3>> comma >> eq1 >> eq2 >>B1>> comma>> eq1 >> eq2 >>H1>> comma >> eq1 >> eq2 >>hh;
// 画矩形
init_figure();//初始化图像网格
::line(a,b,a,b+L1);
::line(a,b+L1,a+H1,b+L1);
::line(a+H1,b+L1,a+H1,b+L1-L2);
rectangle(a+H1,b+L1-L2+2,a+H1+hh,b+L1-2);
::line(a+H1+hh/2,b+L1-L2+2,a+H1+hh/2,b+L1-2);
::line(a+H1,b+L1-L2,a+H1,b+L1-L2-L3/5);
::line(a+H1,b+L1-L2-L3/5,a+H1/3,b);
::line(a,b,a+H1/3,b);
::line(a+H1/4,b,a+H1/4,b-L1/6);
::line(a+H1/4,b-L1/6,a+H1-H1/10,b-L1/6);
::line(a+H1-H1/10,b-L1/6,a+H1-H1/10,b-L1/6+4*L3/5-5*GA);
// 关闭文件
file.close();
/* if(Pz>=1 && Pz<=1.5)
{a=196,b=100,L1=32,L2=15,L3=32,B1=32,H1=25,hh=2.6;}//25
if(Pz>=1.5&&Pz<=3)
{a=496,b=172,L1=40,L2=15,L3=32,B1=40,H1=32,hh=2.6;}//32
if(Pz<1)
{a=96,b=100,L1=32,L2=15,L3=32,B1=32,H1=25,hh=2.6;}
if(Pz>3)
{a=96,b=500,L1=32,L2=15,L3=32,B1=32,H1=25,hh=2.6;}*/
/* init_figure();//初始化图像网格
line(a,b,a,b+L1);
line(a,b+L1,a+H1,b+L1);
line(a+H1,b+L1,a+H1,b+L1-L2);
rectangle(a+H1,b+L1-L2+2,a+H1+hh,b+L1-2);
line(a+H1+hh/2,b+L1-L2+2,a+H1+hh/2,b+L1-2);
line(a+H1,b+L1-L2,a+H1,b+L1-L2-L3/5);
line(a+H1,b+L1-L2-L3/5,a+H1/3,b);
line(a,b,a+H1/3,b);
line(a+H1/4,b,a+H1/4,b-L1/6);
line(a+H1/4,b-L1/6,a+H1-H1/10,b-L1/6);
line(a+H1-H1/10,b-L1/6,a+H1-H1/10,b-L1/6+4*L3/5-5*GA);*/
setrop2(R2_COPYPEN);//当前颜色
setfillcolor(WHITE);
setlinecolor(WHITE);
;//覆盖原进度条区域
setlinestyle(PS_NULL);//无线条
//设置文字填充背景为透明
//计算步骤
EndBatchDraw();//结束缓存区
return 0;
}
int hello()
{
float TD,a,b,L1,L2,L3,B1,H1,hh;
d1=hs/dz;//vc=17,dz=6.5,hs=32;
vf=kv*vc;
n1=1000*vf/(p1*dz);
n2=n1/9550;
P1=T*n2;
Pz=4*P1;
if(Pz>=1 && Pz<=1.5)
{TD=25,a=196,b=100,L1=32,L2=15,L3=32,B1=32,H1=25,hh=2.6;}//25
if(Pz>=1.5&&Pz<=3)
{TD=32,a=496,b=172,L1=40,L2=15,L3=32,B1=40,H1=32,hh=2.6;}//32
FILE *fp = NULL ;
fp = fopen("D:\\cwenjian\\donglixiang2.txt","w") ;
// fprintf(fp,"TD=%f\n a=%f\n b=%f\n L1=%f\n L2=%f\n L3=%f\n B1=%f\n H1=%f\n hh=%f\n",TD,a,b,L1,L2,L3,B1,H1,hh);
fprintf(fp,"TD=%f, a=%f, b=%f, L1=%f, L2=%f, L3=%f, B1=%f, H1=%f, hh=%f",TD,a,b,L1,L2,L3,B1,H1,hh);
fclose(fp);
setrop2(R2_COPYPEN);//当前颜色
setfillcolor(WHITE);
setlinecolor(WHITE);
//覆盖原进度条区域
setlinestyle(PS_NULL);//无线条
//设置文字填充背景为透明
//计算步骤
EndBatchDraw();//结束缓存区
return 0;
}
float snake()//立柱以及侧底座
{
float j,k,B1,H5,H6,N3,N4,B2,B3,H7,H8,H9,N5,N6,N;
j=400,k=100,B1=40,H5=32.5,H6=200,N3=97,N4=66,B2=60,B3=11,H7=56,H8=21,H9=16,N5=71,N6=90,N=19;//H1=6.5
init_figure();//初始化图像网格
rectangle(j,k,j+N3,k+H5);
line(j,k+H5,j-(N5-N4),k+H5+40);
line(j-(N5-N4),k+H5+40,j-(N5-N4),k+H5+H6);
line(j-(N5-N4),k+H5+H6,j-(N5-N4)+N5,k+H5+H6);
line(j-(N5-N4)+N5,k+H5+H6,j-(N5-N4)+N5,k+H5);
rectangle(j,k+H5+H6-15,j+18,k+H5+H6-5);
rectangle(j+30,k+H5+H6-15,j+48,k+H5+H6-5);//立柱
rectangle(j-(N5-N4)-N,k+H5+H6,j-(N5-N4)-N+N6,k+H5+H6+H7);
line(j-(N5-N4)-N,k+H5+H6+H7-4,j-(N5-N4)-N+(2*N6)/3,k+H5+H6+H7-4);
line(j-(N5-N4)-N+(2*N6)/3,k+H5+H6+H7-4,j-(N5-N4)-N+(2*N6)/3+2,k+H5+H6+H7-6);
line(j-(N5-N4)-N+(2*N6)/3+2,k+H5+H6+H7-6,j-(N5-N4)-N+(2*N6)/3+10,k+H5+H6+H7-6);
line(j-(N5-N4)-N+(2*N6)/3+10,k+H5+H6+H7-6,j-(N5-N4)-N+(2*N6)/3+12,k+H5+H6+H7-4);
line(j-(N5-N4)-N+(2*N6)/3+12,k+H5+H6+H7-4,j-(N5-N4)-N+N6-4,k+H5+H6+H7-4);
line(j-(N5-N4)-N+N6-4,k+H5+H6+H7-4,j-(N5-N4)-N+N6-4,k+H5+H6+H7-4-H7/4);
rectangle(j-(N5-N4)-N+N6-8,k+H5+H6+H7-4-H7/2,j-(N5-N4)-N+N6,k+H5+H6+H7-4-H7/4);
rectangle(j-(N5-N4)-N+N6-4,k+H5+H6+3,j-(N5-N4)-N+N6,k+H5+H6+H7-4-H7/2);
circle(j-(N5-N4),k+H5+H6+H7/2,4);
circle(j+N4/3,k+H5+H6/6,4);
circle(j+(4*N4)/5,k+H5+H6/6,4);
circle(j+N4/4,k+H5+(5*H6)/6,4);
circle(j+3*N4/4,k+H5+(5*H6)/6,4);
rectangle(j-(N5-N4)-N+(2*N6)/3+4,k+H5+H6+H7-3,j-(N5-N4)-N+(2*N6)/3+8,k+H5+H6+H7);
setrop2(R2_COPYPEN);//当前颜色
setfillcolor(WHITE);
setlinecolor(WHITE);
//覆盖原进度条区域
setlinestyle(PS_NULL);//无线条
//设置文字填充背景为透明
//计算步骤
EndBatchDraw();//结束缓存区
return 0;
}
float gally()//滑台
{
float m,n,B=32,L=40,H2=107,H3=63,H4=15.5,N1=28,N2=22; //T25
m=466,n=160;
init_figure();//初始化图像网格
rectangle(m,n,m+1.5,n+H3+L+L);
rectangle(m+1.5,n+10,m+2,n+H3+L+L);
rectangle(m+2,n+10,m+4,n+H3+L+14);
rectangle(m+4,n+10,m+2*N2/3+2,n+H3+L+14);
rectangle(m+6,n+10+(H3+L+4)/2-3,m+2*N2/3,n+(H3+L+4)/2+3);
line(m+2,n+10,m+2+N2/5,n+10-H4);
line(m+2+N2/5,n+10-H4,m+2+N2,n+10-H4);
line(m+2+N2,n+10-H4,m+2+N2,n+10);
rectangle(m+2+N2,n+10,m+4+N2,n+12);
rectangle(m+N2-2,n+10,m+N2,n+14+H3+L);
rectangle(m+N2,n+12,m+2+N1,n+12+H3);//滑台运动部件
rectangle(m+N1,n-27.5,m+N1+2,n-11.9);
rectangle(m+N1-1,n-11.9,m+N1+2,n+10);
rectangle(m+N1-1,n+10,m+N1,n+12);
rectangle(m+2+N2-2,n+10+2+H3,m+2+N2,n+14+H3+L);
rectangle(m+2+N2,n+12+H3+L,m+2+N1,n+14+H3+L);
line(m+2*N2/3+2,n+14+H3+L,m+2+N2,n+14+H3+L);
line(m+N1+2,n+10,m+N1+2,n+12);//m+N1+2是滑台右侧横坐标496,n+12是滑台右侧坐标172
setrop2(R2_COPYPEN);//当前颜色
setfillcolor(WHITE);
setlinecolor(WHITE);
//覆盖原进度条区域
setlinestyle(PS_NULL);//无线条
//设置文字填充背景为透明
//计算步骤
EndBatchDraw();//结束缓存区
return 0;
}
float dog()//多轴箱
{
float w,e,B,H,A0,A,h0,h,L0,L,B1,H1,GA=0.1;
w=521,e=237,B=50,H=50,A0=7.5,A=35,h0=15,h=20,L0=8,L=8,B1=40,H1=32;
init_figure();//初始化图像网格
rectangle(w-B/2,e-H/2,w+B/2,e+H/2);
/*line(w-A/2-A0/2-5*GA,e-H/2,w-A/2-A0/2,e-H/2-9*GA);
line(w-A/2-A0/2,e-H/2-9*GA,w-A/2-A0/2+20*GA,e-H/2-9*GA);
line(w-A/2-A0/2+20*GA,e-H/2-9*GA,w-A/2-A0/2+25*GA,e-H/2);
line(w+A/2+A0/2+5*GA,e-H/2,w+A/2+A0/2,e-H/2-9*GA);
line(w+A/2+A0/2,e-H/2-9*GA,w+A/2+A0/2-20*GA,e-H/2-9*GA);
line(w+A/2+A0/2-20*GA,e-H/2-9*GA,w+A/2+A0/2-25*GA,e-H/2);
line(w-A/2,e-H/2,w-A/2,e-H/2-25*GA);
line(w-A/2,e-H/2-25*GA,w+A/2-5*GA,e-H/2-25*GA);
line(w+A/2-5*GA,e-H/2-25*GA,w+A/2+5*GA,e-H/2);
line(w+A/2,e-H/2-10*GA,w-A/2,e-H/2-10*GA);*/
line(w-B/2+L0-5*GA,e+H/2,w-B/2+L0,e+H/2+10*GA);
line(w-B/2+L0,e+H/2+10*GA,w-B/2+L0+L,e+H/2+10*GA);
line(w-B/2+L0+L,e+H/2+10*GA,w-B/2+L0+L+5*GA,e+H/2);
line(w+B/2-L0+5*GA,e+H/2,w+B/2-L0,e+H/2+10*GA);
line(w+B/2-L0,e+H/2+10*GA,w+B/2-L0-L,e+H/2+10*GA);
line(w+B/2-L0-L,e+H/2+10*GA,w+B/2-L0-L-5*GA,e+H/2);
/*rectangle(w-B/2-25*GA,e+H/2-h0-h,w-B/2-10*GA,e+H/2-h0);
line(w-B/2-10*GA,e+H/2-h0-h,w-B/2,e+H/2-h0-h-5*GA);
line(w-B/2-10*GA,e+H/2-h0,w-B/2,e+H/2-h0+5*GA);*/
rectangle(w+B/2+25*GA,e+H/2-h0-h,w+B/2+10*GA,e+H/2-h0);
line(w+B/2+10*GA,e+H/2-h0-h,w+B/2,e+H/2-h0-h-5*GA);
line(w+B/2+10*GA,e+H/2-h0,w+B/2,e+H/2-h0+5*GA);
setlinestyle(PS_DOT);//点线 可以让画的图变成点线
rectangle(w+B1/2,e+H/2-H1,w-B1/2,e+H/2);
rectangle(w+B1/3,e+H/2-(4*H1)/5,w-B1/3,e+H/2-H1/5);
setrop2(R2_COPYPEN);//当前颜色
setfillcolor(WHITE);
setlinecolor(WHITE);
//覆盖原进度条区域
setlinestyle(PS_NULL);//无线条
//设置文字填充背景为透明
//计算步骤
EndBatchDraw();//结束缓存区
return 0;
}
float zt()//总体
{
float m,n,B=32,L=40,H2=107,H3=63,H4=15.5,N1=28,N2=22; //T25
m=466,n=160;
init_figure();//初始化图像网格
rectangle(m,n,m+1.5,n+H3+L+L);
rectangle(m+1.5,n+10,m+2,n+H3+L+L);
rectangle(m+2,n+10,m+4,n+H3+L+14);
rectangle(m+4,n+10,m+2*N2/3+2,n+H3+L+14);
rectangle(m+6,n+10+(H3+L+4)/2-3,m+2*N2/3,n+(H3+L+4)/2+3);
line(m+2,n+10,m+2+N2/5,n+10-H4);
line(m+2+N2/5,n+10-H4,m+2+N2,n+10-H4);
line(m+2+N2,n+10-H4,m+2+N2,n+10);
rectangle(m+2+N2,n+10,m+4+N2,n+12);
rectangle(m+N2-2,n+10,m+N2,n+14+H3+L);
rectangle(m+N2,n+12,m+2+N1,n+12+H3);//滑台运动部件
rectangle(m+N1,n-27.5,m+N1+2,n-11.9);
rectangle(m+N1-1,n-11.9,m+N1+2,n+10);
rectangle(m+N1-1,n+10,m+N1,n+12);
rectangle(m+2+N2-2,n+10+2+H3,m+2+N2,n+14+H3+L);
rectangle(m+2+N2,n+12+H3+L,m+2+N1,n+14+H3+L);
line(m+2*N2/3+2,n+14+H3+L,m+2+N2,n+14+H3+L);
line(m+N1+2,n+10,m+N1+2,n+12);
float j,k,B1,H5,H6,N3,N4,B2,B3,H7,H8,H9,N5,N6,N;
j=400,k=100,B1=40,H5=32.5,H6=200,N3=97,N4=66,B2=60,B3=11,H7=56,H8=21,H9=16,N5=71,N6=90,N=19;
init_figure();//初始化图像网格
rectangle(j,k,j+N3,k+H5);
line(j,k+H5,j-(N5-N4),k+H5+40);
line(j-(N5-N4),k+H5+40,j-(N5-N4),k+H5+H6);
line(j-(N5-N4),k+H5+H6,j-(N5-N4)+N5,k+H5+H6);
line(j-(N5-N4)+N5,k+H5+H6,j-(N5-N4)+N5,k+H5);
rectangle(j,k+H5+H6-15,j+18,k+H5+H6-5);
rectangle(j+30,k+H5+H6-15,j+48,k+H5+H6-5);//立柱
rectangle(j-(N5-N4)-N,k+H5+H6,j-(N5-N4)-N+N6,k+H5+H6+H7);
line(j-(N5-N4)-N,k+H5+H6+H7-4,j-(N5-N4)-N+(2*N6)/3,k+H5+H6+H7-4);
line(j-(N5-N4)-N+(2*N6)/3,k+H5+H6+H7-4,j-(N5-N4)-N+(2*N6)/3+2,k+H5+H6+H7-6);
line(j-(N5-N4)-N+(2*N6)/3+2,k+H5+H6+H7-6,j-(N5-N4)-N+(2*N6)/3+10,k+H5+H6+H7-6);
line(j-(N5-N4)-N+(2*N6)/3+10,k+H5+H6+H7-6,j-(N5-N4)-N+(2*N6)/3+12,k+H5+H6+H7-4);
line(j-(N5-N4)-N+(2*N6)/3+12,k+H5+H6+H7-4,j-(N5-N4)-N+N6-4,k+H5+H6+H7-4);
line(j-(N5-N4)-N+N6-4,k+H5+H6+H7-4,j-(N5-N4)-N+N6-4,k+H5+H6+H7-4-H7/4);
rectangle(j-(N5-N4)-N+N6-8,k+H5+H6+H7-4-H7/2,j-(N5-N4)-N+N6,k+H5+H6+H7-4-H7/4);
rectangle(j-(N5-N4)-N+N6-4,k+H5+H6+3,j-(N5-N4)-N+N6,k+H5+H6+H7-4-H7/2);
circle(j-(N5-N4),k+H5+H6+H7/2,4);
circle(j+N4/3,k+H5+H6/6,4);
circle(j+(4*N4)/5,k+H5+H6/6,4);
circle(j+N4/4,k+H5+(5*H6)/6,4);
circle(j+3*N4/4,k+H5+(5*H6)/6,4);
rectangle(j-(N5-N4)-N+(2*N6)/3+4,k+H5+H6+H7-3,j-(N5-N4)-N+(2*N6)/3+8,k+H5+H6+H7);
float a,b,L1,L2,L3,H1,hh,TD;
d1=hs/dz;
vf=kv*vc;
n1=1000*vf/(p1*dz);
n2=n1/9550;
P1=T*n2;
Pz=4*P1;
if(Pz>=1 && Pz<=1.5)
{TD=25,a=196,b=100,L1=32,L2=15,L3=32,B1=32,H1=25,hh=2.6;}//25
if(Pz>=1.5&&Pz<=3)
{TD=32,a=496,b=172,L1=40,L2=15,L3=32,B1=40,H1=32,hh=2.6;}//32
init_figure();//初始化图像网格
line(a,b,a,b+L1);
line(a,b+L1,a+H1,b+L1);
line(a+H1,b+L1,a+H1,b+L1-L2);
rectangle(a+H1,b+L1-L2+2,a+H1+hh,b+L1-2);
line(a+H1+hh/2,b+L1-L2+2,a+H1+hh/2,b+L1-2);
line(a+H1,b+L1-L2,a+H1,b+L1-L2-L3/5);
line(a+H1,b+L1-L2-L3/5,a+H1/3,b);
line(a,b,a+H1/3,b);
line(a+H1/4,b,a+H1/4,b-L1/6);
line(a+H1/4,b-L1/6,a+H1-H1/10,b-L1/6);
line(a+H1-H1/10,b-L1/6,a+H1-H1/10,b-L1/6+4*L3/5-5*GA);
setrop2(R2_COPYPEN);//当前颜色
setfillcolor(WHITE);
setlinecolor(WHITE);
//覆盖原进度条区域
setlinestyle(PS_NULL);//无线条
//设置文字填充背景为透明
//计算步骤
EndBatchDraw();//结束缓存区
return 0;
}
void pg(float x,float y,float N2D,float N1D,float H3D,float a,float b,float L1,float L2,float L3,float B1,float H1,float hh);
float hhh()//运动
{
float H3D=63,N1D=28,N2D=22,x=466,y=160,a,b,L1,L2,L3,B1,H1,hh;
//初始坐标
d1=hs/dz;//vc=17,dz=6.5,hs=32
vf=kv*vc;
n1=1000*vf/(p1*dz);
n2=n1/9550;
P1=T*n2;
Pz=4*P1;
if(Pz>=1 && Pz<=1.5)
{a=196,b=100,L1=32,L2=15,L3=32,B1=32,H1=25,hh=2.6;}//25
if(Pz>=1.5&&Pz<=3)
{a=496,b=172,L1=40,L2=15,L3=32,B1=40,H1=32,hh=2.6;}//32
if(Pz<1)
{a=96,b=100,L1=32,L2=15,L3=32,B1=32,H1=25,hh=2.6;}
if(Pz>3)
{a=96,b=500,L1=32,L2=15,L3=32,B1=32,H1=25,hh=2.6;}
float xSize = 1, ySize = 1,aSize=1,bSize=1; //每次移动的方向和距离
while (1)
{
BeginBatchDraw();
cleardevice();
if ( y>196)
{
ySize = 0;
Sleep(3000);
ySize=-1;
}
if(y<160)
{
ySize=0;
}
y += ySize; //y移动
if ( b>208)
{
bSize = 0;
Sleep(3000);
bSize=-1;
}
if(b<172)
{
bSize=0;
}
b += bSize;
pg(x, y, N2D,N1D,H3D,a,b,L1,L2,L3,B1,H1,hh);
FlushBatchDraw();
}
EndBatchDraw();//结束缓存区
_getch();
closegraph();
return 0;
}
void pg(float x,float y,float N2D,float N1D,float H3D,float a,float b,float L1,float L2,float L3,float B1,float H1,float hh)//a,b,L1,L2,L3,B1,H1,hh;
{
cleardevice(); //清屏
setcolor(BLUE);
rectangle(x+N2D,y+12,x+2+N1D,y+12+H3D);//绘制
line(a,b,a,b+L1);
line(a,b+L1,a+H1,b+L1);
line(a+H1,b+L1,a+H1,b+L1-L2);
rectangle(a+H1,b+L1-L2+2,a+H1+hh,b+L1-2);
line(a+H1+hh/2,b+L1-L2+2,a+H1+hh/2,b+L1-2);
line(a+H1,b+L1-L2,a+H1,b+L1-L2-L3/5);
line(a+H1,b+L1-L2-L3/5,a+H1/3,b);
line(a,b,a+H1/3,b);
line(a+H1/4,b,a+H1/4,b-L1/6);
line(a+H1/4,b-L1/6,a+H1-H1/10,b-L1/6);
line(a+H1-H1/10,b-L1/6,a+H1-H1/10,b-L1/6+4*L3/5-5*GA);
init_figure();
float m,n,B=32,L=40,H2=107,H3=63,H4=15.5,N1=28,N2=22; //T25
m=466,n=160;
//滑台
init_figure();//初始化图像网格
rectangle(m,n,m+1.5,n+H3+L+L);
rectangle(m+1.5,n+10,m+2,n+H3+L+L);
rectangle(m+2,n+10,m+4,n+H3+L+14);
rectangle(m+4,n+10,m+2*N2/3+2,n+H3+L+14);
rectangle(m+6,n+10+(H3+L+4)/2-3,m+2*N2/3,n+(H3+L+4)/2+3);
line(m+2,n+10,m+2+N2/5,n+10-H4);
line(m+2+N2/5,n+10-H4,m+2+N2,n+10-H4);
line(m+2+N2,n+10-H4,m+2+N2,n+10);
rectangle(m+2+N2,n+10,m+4+N2,n+12);
rectangle(m+N2-2,n+10,m+N2,n+14+H3+L);
rectangle(m+N1,n-27.5,m+N1+2,n-11.9);
rectangle(m+N1-1,n-11.9,m+N1+2,n+10);
rectangle(m+N1-1,n+10,m+N1,n+12);
rectangle(m+2+N2-2,n+10+2+H3,m+2+N2,n+14+H3+L);
rectangle(m+2+N2,n+12+H3+L,m+2+N1,n+14+H3+L);
line(m+2*N2/3+2,n+14+H3+L,m+2+N2,n+14+H3+L);
line(m+N1+2,n+10,m+N1+2,n+12);
init_figure();
Sleep(10);
}
int main()
{
int i,event=0;
char s[30];//输入字符串变量
short win_width,win_height;//定义窗口的宽度和高度
win_width = 1640;win_height = 760;
initgraph(win_width,win_height);//初始化窗口(黑屏)
for(i=0;i<256;i+=5)
{
setbkcolor(RGB(i,i,i));//设置背景色,原来默认黑色
cleardevice();//清屏(取决于背景色)
Sleep(30);//延时30ms
}
RECT R1={r[0][0],r[0][1],r[0][2],r[0][3]};
RECT R2={r[1][0],r[1][1],r[1][2],r[1][3]};
RECT R3={r[2][0],r[2][1],r[2][2],r[2][3]};
RECT R4={r[3][0],r[3][1],r[3][2],r[3][3]};
RECT R5={r[4][0],r[4][1],r[4][2],r[4][3]};
RECT R6={r[5][0],r[5][1],r[5][2],r[5][3]};
RECT R7={r[6][0],r[6][1],r[6][2],r[6][3]};
RECT R8={r[7][0],r[7][1],r[7][2],r[7][3]};
RECT R9={r[8][0],r[8][1],r[8][2],r[8][3]};
LOGFONT f;//字体样式指针
gettextstyle(&f); //获取字体样式
_tcscpy(f.lfFaceName,_T("宋体")); //设置字体为宋体
f.lfQuality = ANTIALIASED_QUALITY; // 设置输出效果为抗锯齿
settextstyle(&f); // 设置字体样式
settextcolor(BLACK); //BLACK在graphic.h头文件里面被定义为黑色的颜色常量
drawtext("输入参数",&R1,DT_CENTER | DT_VCENTER | DT_SINGLELINE);//在矩形区域R1内输入文字,水平居中,垂直居中,单行显示
drawtext("多轴箱",&R2,DT_CENTER | DT_VCENTER | DT_SINGLELINE);//在矩形区域R2内输入文字,水平居中,垂直居中,单行显示
drawtext("动力箱",&R3,DT_CENTER | DT_VCENTER | DT_SINGLELINE);//在矩形区域R3内输入文字,水平居中,垂直居中,单行显示
drawtext("滑台",&R4,DT_CENTER | DT_VCENTER | DT_SINGLELINE);
drawtext("立柱",&R5,DT_CENTER | DT_VCENTER | DT_SINGLELINE);
drawtext("总体",&R6,DT_CENTER | DT_VCENTER | DT_SINGLELINE);
drawtext("运动",&R7,DT_CENTER | DT_VCENTER | DT_SINGLELINE);
drawtext("动力箱数据",&R8,DT_CENTER | DT_VCENTER | DT_SINGLELINE);
drawtext("退出",&R9,DT_CENTER | DT_VCENTER | DT_SINGLELINE);
setlinecolor(BLUE);
rectangle(r[0][0],r[0][1],r[0][2],r[0][3]);
rectangle(r[1][0],r[1][1],r[1][2],r[1][3]);
rectangle(r[2][0],r[2][1],r[2][2],r[2][3]);
rectangle(r[3][0],r[3][1],r[3][2],r[3][3]);
rectangle(r[4][0],r[4][1],r[4][2],r[4][3]);
rectangle(r[5][0],r[5][1],r[5][2],r[5][3]);
rectangle(r[6][0],r[6][1],r[6][2],r[6][3]);
rectangle(r[7][0],r[7][1],r[7][2],r[7][3]);
rectangle(r[8][0],r[8][1],r[8][2],r[8][3]);
MOUSEMSG m;//鼠标指针
writehuatai();
//writedonglixiang();
writelizhu();
writeduozhouxiang();
while(true)
{
m = GetMouseMsg();//获取一条鼠标消息
switch(m.uMsg)
{
case WM_MOUSEMOVE:
setrop2(R2_XORPEN);
setlinecolor(LIGHTCYAN);//线条颜色为亮青色
setlinestyle(PS_SOLID, 3);//设置画线样式为实现,10磅
setfillcolor(RED);//填充颜色为白色
if(button_judge(m.x,m.y)!=0)
{
if(event != button_judge(m.x,m.y))
{
event = button_judge(m.x,m.y);//记录这一次触发的按钮
fillrectangle(r[event-1][0],r[event-1][1],r[event-1][2],r[event-1][3]);//有框填充矩形(X1,Y1,X2,Y2)
}
}
else
{
if(event!=0)//上次触发的按钮未被修正为原来的颜色
{
fillrectangle(r[event-1][0],r[event-1][1],r[event-1][2],r[event-1][3]);//两次同或为原来颜色
event = 0;
}
}
break;
case WM_LBUTTONDOWN:
setrop2(R2_NOTXORPEN);//二元光栅——NOT(屏幕颜色 XOR 当前颜色)
for(i=0;i<=10;i++)
{
setlinecolor(RGB(25*i,25*i,25*i));//设置圆颜色
circle(m.x,m.y,2*i);
Sleep(20);//停顿30ms
circle(m.x,m.y,2*i);//抹去刚刚画的圆
}
//按照按钮判断左键单击后的操作
switch(button_judge(m.x,m.y))
{
//复原按钮原型
case 1:
InputBox(s,30,"请输入加工孔长度,钻头直径,切削速度");
sscanf(s,"%f%f%f",&hs,&dz,&vc);//将输入字符串依次扫描到全局变量里面
break;
case 2:
dog();//仿真运行
FlushMouseMsgBuffer();//单击事件后清空鼠标消息
break;
case 3:
simulation();//仿真运行
FlushMouseMsgBuffer();//单击事件后清空鼠标消息
break;
case 4:
gally();//仿真运行
FlushMouseMsgBuffer();//单击事件后清空鼠标消息
break;
case 5:
snake();//仿真运行
FlushMouseMsgBuffer();//单击事件后清空鼠标消息
break;
case 6:
zt();//仿真运行
FlushMouseMsgBuffer();//单击事件后清空鼠标消息
break;
case 7:
hhh();//仿真运行
FlushMouseMsgBuffer();//单击事件后清空鼠标消息
break;
case 8:
hello();//仿真运行
FlushMouseMsgBuffer();//单击事件后清空鼠标消息
break;
case 9:
closegraph();//关闭绘图环境
exit(0);//正常退出
default:
FlushMouseMsgBuffer();//单击事件后清空鼠标消息
//printf("\r\n(%d,%d)",m.x,m.y);//打印鼠标坐标,方便调试时确定区域
break;
}
break;
}
}
return 0;
}
这是完整的代码,问题主要出在动力箱部分,理论上动力箱点一下应该出现图形的,结果却没有反应(问题再104行到141行之间)