想问一个if语句的用法
我的想法是定义两个数Bd,H,当350<Bd<450,350<H<450时{a=196,b=100,L1=32,L2=15,L3=32,B1=32,H1=25,hh=2.6;}当450=<Bd<550,450=<H<550时{a=496,b=172,L1=40,L2=15,L3=32,B1=40,H1=32,hh=2.6;}
float simulation()//动力箱
{
float Bd,H,a,b,L1,L2,L3,B1,H1,hh;
if(Bd>350 && Bd<450 && H>350 && H<450)
{a=196,b=100,L1=32,L2=15,L3=32,B1=32,H1=25,hh=2.6;}//25
if(Bd>=450&&Bd<=550&&H>=450&&H<=550)
{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;
}
这是用到这部分代码的部分
输入Bd和H我用的switch语句 case 2:
InputBox(s,30,"请输入");
sscanf(s,"%f%f",&Bd,&H);//将输入字符串依次扫描到全局变量里面
simulation();//仿真运行
FlushMouseMsgBuffer();//单击事件后清空鼠标消息
break;
但是我输入Bd和H的值之后 明明在if语句的范围内 但是却不会出现图形,不知道是哪里出现的问题
下面是完整的代码
#include <graphics.h> // 引用图形库头文件
#include <conio.h>
#include <stdio.h>
#include <windows.h> //用到了定时函数sleep()
#include <math.h>
#include <string.h>
#define PI 3.1416
int r={{0,20,130,60},{130,20,260,60},{260,20,390,60},{390,20,520,60},{520,20,650,60},{650,20,780,60},{800,20,890,60}};//三个按钮的二维数组
float Bd,H,q,GA=1;//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 && x<r && y>r && y<r)return 1;
if(x>r && x<r && y>r && y<r)return 2;
if(x>r && x<r && y>r && y<r)return 3;
if(x>r && x<r && y>r && y<r)return 4;
if(x>r && x<r && y>r && y<r)return 5;
if(x>r && x<r && y>r && y<r)return 6;
if(x>r && x<r && y>r && y<r)return 7;
return 0;
}
//初始化图像
void init_figure()
{
int i;
setrop2(R2_COPYPEN);//当前颜色
setlinecolor(BLACK);
setlinestyle(PS_SOLID);//实线
//外框线
//点线
//水平辅助线
}
//仿真运行
float simulation()//动力箱
{
float Bd,H,a,b,L1,L2,L3,B1,H1,hh;
if(Bd>350 && Bd<450 && H>350 && H<450)
{a=196,b=100,L1=32,L2=15,L3=32,B1=32,H1=25,hh=2.6;}//25
if(Bd>=450&&Bd<=550&&H>=450&&H<=550)
{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;
}
int hello()
{
float c,d;
c=60,d=368.5;
init_figure();//初始化图像网格
rectangle(c,d,c+11,d+20);
rectangle(c+11,d,c+49,d+16);
rectangle(c+49,d,c+60,d+20);
line(c+6,d-15,c+6,d);
line(c+54,d,c+54,d-15);
line(c+11,d-15,c,d-15);
line(c,d-15,c,d-33);
line(c,d-33,c+5,d-33);
line(c+5,d-33,c+6,d-36);
line(c+49,d-15,c+60,d-15);
line(c+60,d-15,120,d-33);
line(c+60,d-33,c+55,d-33);
line(c+55,d-33,c+54,d-36);
line(c+54,d-36,c+6,d-36);
line(c+11,d-15,c+12,d-17);
line(c+49,d-15,c+48,d-17);
rectangle(c+12,d-30,c+48,d-17);
rectangle(c+10,d-268.5,c+50,d-36);
rectangle(c+10,d-268.5,c+50,d-236);
line(c+10,d-40.5,c+15,d-40.5);
line(c+15,d-40.5,c+15,d-48.5);
line(c+15,d-48.5,c+10,d-53.5);
line(c+50,d-40.5,c+45,d-40.5);
line(c+45,d-40.5,c+45,d-40.5);
line(c+45,d-48.5,c+50,d-53.5);
rectangle(c+20,d-53.5,c+40,d-40.5);
rectangle(c+22,d-48.5,c+38,d-40.5);
line(c+20,d-53.5,c+22,d-48.5);
line(c+40,d-53.5,c+38,d-48.5);
rectangle(c+9,d-68.5,c+10,d-58.5);
rectangle(c+51,d-68.5,c+50,d-58.5);
rectangle(c+17.5,d-195,c+42.5,d-143);
rectangle(c+17.5,d-143,c+25,d-101);
rectangle(c+42.5,d-143,c+35,d-101);
line(c+20,d-143,c+20,d-101);
line(c+40,d-143,c+40,d-101);
rectangle(c+27.5,d-101,c+32.5,d-78.5);
line(c+25,d-101,c+35,d-101);
line(c+23,d-101,c+23,d-78.5);
line(c+23,d-78.5,c+15,d-78.5);
line(c+15,d-78.5,c+15,d-200.4);
line(c+15,d-78.5,c+15,d-200.4);
line(c+15,d-200.4,c+23,d-200.4);
line(c+23,d-200.4,c+23,d-195);
line(c+37,d-101,c+37,d-78.5);
line(c+37,d-78.5,c+45,d-78.5);
line(c+45,d-78.5,c+45,d-200.4);
line(c+45,d-200.4,c+37,d-200.4);
line(c+37,d-200.4,c+37,d-195);
rectangle(c+17.5,d-196.5,c+23,d-195);
rectangle(c+42.5,d-196.5,c+37,d-195);
rectangle(c+23,d-198.5,c+29,d-195);
rectangle(c+37,d-198.5,c+31,d-195);
rectangle(c+31,d-195,c+29,d-196.5);
rectangle(c+24,d-210.4,c+28,d-198.5);
rectangle(c+36,d-210.4,c+32,d-198.5);
rectangle(c+25,d-236,c+27,d-210.4);
rectangle(c+35,d-236,c+33,d-210.4);
line(c+27,d-220.4,c+33,d-220.4);
rectangle(c+25,d-108.5,c+35,d-101);
rectangle(c+25,d-104,c+35,d-101);
rectangle(c+27,d-110.5,c+33,d-108.5);
rectangle(c+8,d-163.5,c+12,d-153.5);
rectangle(c+9,d-208.5,c+10,d-195);
rectangle(c+51,d-208.5,c+50,d-195);
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,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;
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=1;
w=850,e=400,B=500,H=500,A0=75,A=350,h0=150,h=200,L0=80,L=80,B1=400,H1=320;
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;
}
void pg(float x, float y);
int hhh()//运动
{
int x = 120, y = 140;//初始坐标
int xSize = 1, ySize = 1;//每次移动的方向和距离
while (1)
{
BeginBatchDraw();
cleardevice();
if ( y+100>500)
{
ySize = 0;
Sleep(3000);
ySize=-1;
}
if(y<140)
{
ySize=0;
}
y += ySize;//y移动
pg(x, y);
FlushBatchDraw();
}
EndBatchDraw();//结束缓存区
_getch();
closegraph();
return 0;
}
void pg(float x,float y)
{
cleardevice(); //清屏
setcolor(BLUE);
rectangle(x,y,x+100,y+100);//绘制
init_figure();
float w,e;
w=0,e=0;
//初始化图像网格
rectangle(w+600,e+150,w+1100,e+650);
line(w+635,e+150,w+639,e+142);
line(w+639,e+142,w+660,e+142);
line(w+660,e+142,w+664,e+150);
line(w+1065,e+150,w+1061,e+142);
line(w+1061,e+142,w+1040,e+142);
line(w+1040,e+142,w+1036,e+150);
line(w+675,e+150,w+675,e+125);
line(w+675,e+125,w+1020,e+125);
line(w+1020,e+125,w+1030,e+150);
line(w+675,e+140,w+1025,e+140);
rectangle(w+590,e+500,w+575,e+300);
line(w+590,e+500,w+600,e+510);
line(w+590,e+300,w+600,e+290);
line(w+680,e+655,w+770,e+655);
line(w+680,e+655,w+675,e+650);
line(w+770,e+655,w+775,e+650);
line(w+1020,e+655,w+930,e+655);
line(w+1020,e+655,w+1025,e+650);
line(w+930,e+655,w+925,e+650);
rectangle(w+1125,e+500,w+1110,e+300);
line(w+1110,e+300,w+1100,e+290);
line(w+1110,e+500,w+1100,e+510);
setlinestyle(PS_DOT);//点线
rectangle(w+690,e+400,w+1010,e+650);
rectangle(w+730,e+450,w+960,e+610);
line(w+670,e+630,w+1030,e+630);//多轴
setlinestyle(PS_SOLID);//实线
rectangle(w+1150,e+650,w+1420,e+655);
line(w+1150,e+650,w+1490,e+650);
line(w+1150,e+650,w+1150,e+300);
line(w+1150,e+300,w+1155,e+290);
line(w+1155,e+290,w+1155,e+150);
line(w+1155,e+150,w+1240,e+150);
line(w+1240,e+150,w+1250,e+140);
rectangle(w+1250,e+125,w+1420,e+140);
line(w+1420,e+140,w+1425,e+150);
line(w+1425,e+150,w+1490,e+150);
line(w+1490,e+150,w+1490,e+650);//外形
rectangle(w+1183,e+170,w+1241.5,e+630);//左
rectangle(w+1480,e+630,w+1421.5,e+170);//右
rectangle(w+1285,e+170,w+1375,e+630);//中
rectangle(w+1183,e+185,w+1251.5,e+615);//左
rectangle(w+1480,e+615,w+1411.5,e+185);//右
setlinestyle(PS_DOT);//点线
rectangle(w+1264.5,e+300,w+1404.5,e+500);//中
setlinestyle(PS_SOLID);//实线
//猜测
rectangle(w+1150,e+400,w+1155,e+610);
rectangle(w+1183,e+190,w+1241.5,e+260);//左
rectangle(w+1480,e+260,w+1421.5,e+190);//右
line(w+1480,e+350,w+1421.5,e+350);
line(w+1183,e+350,w+1241.5,e+350);
line(w+1183,e+420,w+1241.5,e+420);
line(w+1480,e+420,w+1421.5,e+420);
line(w+1480,e+510,w+1421.5,e+510);
line(w+1183,e+510,w+1241.5,e+510);//动力箱法兰
float m,n;
m=400,n=100;
init_figure();//初始化图像网格
rectangle(m+66,n+60,m+67.5,n+205);
rectangle(m+67.5,n+73.5,m+68,n+205);
rectangle(m+68,n+73.5,m+70,n+167);
rectangle(m+70,n+73.5,m+80,n+167);
rectangle(m+73,n+112,m+77,n+120);
line(m+68,n+73.5,m+72,n+68.1);
line(m+72,n+68.1,m+80,n+68.1);
line(m+80,n+68.1,m+80,n+73.5);
line(m+68,n+73.5,m+80,n+73.5);
line(m+72,n+68.1,m+72,n+58.1);
line(m+72,n+58.1,m+88,n+58.1);
line(m+88,n+48.1,m+88,n+73.5);
line(m+74,n+58.1,m+74,n+48.1);
line(m+74,n+48.1,m+88,n+48.1);
rectangle(m+82,n+125.5,m+88,n+167.5);
rectangle(m+82,n+73.5,m+85,n+167.5);
rectangle(m+85,n+73.5,m+88,n+75.5);
rectangle(m+95,n+32.5,m+97,n+52.5);
rectangle(m+94,n+52.5,m+97,n+73.5);
rectangle(m+94,n+73.5,m+95,n+75.5);
rectangle(m+85,n+75.5,m+97,n+125.5);
float c,d;
c=60,d=368.5;
init_figure();//初始化图像网格
rectangle(c,d,c+11,d+20);
rectangle(c+11,d,c+49,d+16);
rectangle(c+49,d,c+60,d+20);
line(c+6,d-15,c+6,d);
line(c+54,d,c+54,d-15);
line(c+11,d-15,c,d-15);
line(c,d-15,c,d-33);
line(c,d-33,c+5,d-33);
line(c+5,d-33,c+6,d-36);
line(c+49,d-15,c+60,d-15);
line(c+60,d-15,120,d-33);
line(c+60,d-33,c+55,d-33);
line(c+55,d-33,c+54,d-36);
line(c+54,d-36,c+6,d-36);
line(c+11,d-15,c+12,d-17);
line(c+49,d-15,c+48,d-17);
rectangle(c+12,d-30,c+48,d-17);
rectangle(c+10,d-268.5,c+50,d-36);
rectangle(c+10,d-268.5,c+50,d-236);
line(c+10,d-40.5,c+15,d-40.5);
line(c+15,d-40.5,c+15,d-48.5);
line(c+15,d-48.5,c+10,d-53.5);
line(c+50,d-40.5,c+45,d-40.5);
line(c+45,d-40.5,c+45,d-40.5);
line(c+45,d-48.5,c+50,d-53.5);
rectangle(c+20,d-53.5,c+40,d-40.5);
rectangle(c+22,d-48.5,c+38,d-40.5);
line(c+20,d-53.5,c+22,d-48.5);
line(c+40,d-53.5,c+38,d-48.5);
rectangle(c+9,d-68.5,c+10,d-58.5);
rectangle(c+51,d-68.5,c+50,d-58.5);
rectangle(c+17.5,d-195,c+42.5,d-143);
rectangle(c+17.5,d-143,c+25,d-101);
rectangle(c+42.5,d-143,c+35,d-101);
line(c+20,d-143,c+20,d-101);
line(c+40,d-143,c+40,d-101);
rectangle(c+27.5,d-101,c+32.5,d-78.5);
line(c+25,d-101,c+35,d-101);
line(c+23,d-101,c+23,d-78.5);
line(c+23,d-78.5,c+15,d-78.5);
line(c+15,d-78.5,c+15,d-200.4);
line(c+15,d-78.5,c+15,d-200.4);
line(c+15,d-200.4,c+23,d-200.4);
line(c+23,d-200.4,c+23,d-195);
line(c+37,d-101,c+37,d-78.5);
line(c+37,d-78.5,c+45,d-78.5);
line(c+45,d-78.5,c+45,d-200.4);
line(c+45,d-200.4,c+37,d-200.4);
line(c+37,d-200.4,c+37,d-195);
rectangle(c+17.5,d-196.5,c+23,d-195);
rectangle(c+42.5,d-196.5,c+37,d-195);
rectangle(c+23,d-198.5,c+29,d-195);
rectangle(c+37,d-198.5,c+31,d-195);
rectangle(c+31,d-195,c+29,d-196.5);
rectangle(c+24,d-210.4,c+28,d-198.5);
rectangle(c+36,d-210.4,c+32,d-198.5);
rectangle(c+25,d-236,c+27,d-210.4);
rectangle(c+35,d-236,c+33,d-210.4);
line(c+27,d-220.4,c+33,d-220.4);
rectangle(c+25,d-108.5,c+35,d-101);
rectangle(c+25,d-104,c+35,d-101);
rectangle(c+27,d-110.5,c+33,d-108.5);
rectangle(c+8,d-163.5,c+12,d-153.5);
rectangle(c+9,d-208.5,c+10,d-195);
rectangle(c+51,d-208.5,c+50,d-195);
float j,k;
j=400,k=100;
init_figure();//初始化图像网格
//h5
rectangle(j,k,j+97,k+32.5);
//斜线
line(j,k+32.5,j-5,k+92.5);
//h6 h2 h3 h4
line(j-5,k+232.5,j-5,k+92.5);
//n5
line(j-5,k+232.5,j+66,k+232.5);
line(j+66,k+32.5,j+66,k+232.5);
rectangle(j,k+215,j+20,k+228);
rectangle(j+35,k+215,j+55,k+228);
float p,q;
p=400,q=100;//侧底座数据
line(p-5,q+232.5,p-5,q+288.5);
line(p-5,q+288.5,p+66,q+288.5);
line(p-5,q+284.5,p+26,q+284.5);
line(p-5,q+232.5,p+66,q+232.5);
line(p+26,q+284.5,p+28,q+282.5);
line(p+28,q+282.5,p+35,q+282.5);
line(p+35,q+282.5,p+37,q+284.5);
line(p+37,q+284.5,p+62,q+284.5);
rectangle(p+29,q+286.5,p+34,q+288.5);
line(p+62,q+284.5,p+62,q+264.5);
line(p+66,q+288.5,p+66,q+264.5);
line(p+66,q+264.5,p+60,q+264.5);
line(p+60,q+264.5,p+60,q+258.5);
line(p+60,q+258.5,p+66,q+258.5);
line(p+66,q+258.5,p+66,q+232.5);
rectangle(p+62,q+235.5,p+66,q+258.5);
circle(p,q+260,2);
init_figure();
Sleep(10);
}
int main()
{
int i,event=0;
char s;//输入字符串变量
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,r,r,r};
RECT R2={r,r,r,r};
RECT R3={r,r,r,r};
RECT R4={r,r,r,r};
RECT R5={r,r,r,r};
RECT R6={r,r,r,r};
RECT R7={r,r,r,r};
LOGFONT f;//字体样式指针
gettextstyle(&f); //获取字体样式
_tcscpy(f.lfFaceName,_T("宋体")); //设置字体为宋体
f.lfQuality = ANTIALIASED_QUALITY; // 设置输出效果为抗锯齿
settextstyle(&f); // 设置字体样式
settextcolor(BLACK); //BLACK在graphic.h头文件里面被定义为黑色的颜色常量
drawtext("11",&R1,DT_CENTER | DT_VCENTER | DT_SINGLELINE);//在矩形区域R1内输入文字,水平居中,垂直居中,单行显示
drawtext("11",&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);
setlinecolor(BLUE);
rectangle(r,r,r,r);
rectangle(r,r,r,r);
rectangle(r,r,r,r);
rectangle(r,r,r,r);
rectangle(r,r,r,r);
rectangle(r,r,r,r);
rectangle(r,r,r,r);
MOUSEMSG m;//鼠标指针
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,r,r,r);//有框填充矩形(X1,Y1,X2,Y2)
}
}
else
{
if(event!=0)//上次触发的按钮未被修正为原来的颜色
{
fillrectangle(r,r,r,r);//两次同或为原来颜色
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:
hello();//将输入字符串依次扫描到全局变量里面
FlushMouseMsgBuffer();//单击事件后清空鼠标消息
break;
case 2:
InputBox(s,30,"请输入");
sscanf(s,"%f%f",&Bd,&H);//将输入字符串依次扫描到全局变量里面
simulation();//仿真运行
FlushMouseMsgBuffer();//单击事件后清空鼠标消息
break;
case 3:
snake();//仿真运行
FlushMouseMsgBuffer();//单击事件后清空鼠标消息
break;
case 4:
gally();//仿真运行
FlushMouseMsgBuffer();//单击事件后清空鼠标消息
break;
case 5:
dog();//仿真运行
FlushMouseMsgBuffer();//单击事件后清空鼠标消息
break;
case 6:
hhh();//仿真运行
FlushMouseMsgBuffer();//单击事件后清空鼠标消息
break;
case 7:
closegraph();//关闭绘图环境
exit(0);//正常退出
default:
FlushMouseMsgBuffer();//单击事件后清空鼠标消息
//printf("\r\n(%d,%d)",m.x,m.y);//打印鼠标坐标,方便调试时确定区域
break;
}
break;
}
}
return 0;
}
这是完整的代码 问题主要在float simulation()这组函数中,希望有大佬帮忙解答
if(Bd>350 && Bd<450 && H>350 && H<450)这个应该没啥问题啊 不都是并行的关系吗 wp231957 发表于 2023-4-4 15:57
if(Bd>350 && Bd350 && H
但是我输入Bd=400,H=400这种明明在范围内的数,却不会出现图形,如果我把if语句删掉,单纯赋值又能出现 图形,我觉得应该是if语句没用对
页:
[1]