我的网站 :http://www.tigerion.cn
/*操作说明:
Tab:竖直移动 空格:水平选择
加下划线字母 快捷键
<:减少 >:增加
E:退出
*/
#include
#include
#include
#include
#include
#include
#include
int locy[4]={370,405,430,455};/*四紫灯的竖坐标*/
struct
{
float infor[4];/*infor[1]:signal,2: frequency,3: B,4: A*/
}CH[2];
void lightswitch(int x,int y,int r,int color,int key);/*开关指示灯*/
void main()
{
int gd=DETECT,gm;
void drawboard();/*画面板*/
void contrlcenter();/*控制中心*/
registerbgidriver(EGAVGA_driver);
initgraph(&gd,&gm,"");
drawboard();
contrlcenter();
getch();
closegraph();
}
void smallimage(int i,int j); /* 画控制面板中显示的信号模式*/
void drawboard()/*画面板*/
{
int i,k;
float j,x,y;
char pattern[8]={-1,-61,-91,-103,-103,-91,-61,-1};
/*背景*/
setfillpattern(pattern,13);
setfillstyle(12,13);
bar(0,0,640,480);
/*屏幕*/
setlinestyle(0,0,3);
setcolor(15);
rectangle(40,40,600,300);
setfillstyle(1,0);
bar(43,43,597,297);
setcolor(7);
line(230,43,230,297);
line(43,170,227,170);
setcolor(2);
outtextxy(120,45,"CHX");
outtextxy(120,175,"CHY");
setlinestyle(0,0,1);
line(240,290,240,270);
line(240,270,237,273);
line(240,290,260,290);
line(260,290,257,293);
outtextxy(242,268,"y");
outtextxy(254,282,"x");
/*控制面板*/
setlinestyle(0,0,3);
setcolor(2);
rectangle(40,320,600,470);
setfillstyle(1,3);
bar(42,322,598,468);
setcolor(6);
line(365,320,365,470);
setfillstyle(1,1);
bar(367,322,598,468);
setlinestyle(0,0,1);
setcolor(3);
line(368,358,597,358);
line(368,406,597,406);
setlinestyle(1,0,3);
setcolor(7);
line(225,323,225,467);
setcolor(4);
setlinestyle(0,0,1);
circle(178,344,8);
circle(318,344,8);
setcolor(14);
outtextxy(140,340,"CHX");
outtextxy(280,340,"CHY");
outtextxy(80,341,"Exit");
outtextxy(55,366,"S");
outtextxy(55,401,"F");
outtextxy(55,426,"B");
outtextxy(55,451,"A");
setcolor(4);
line(80,349,88,349);
setcolor(5);
circle(85,370,5);
circle(85,405,5);
circle(85,430,5);
circle(85,455,5);
setcolor(12);
setfillstyle(1,12);
circle(62,342,10);
circle(62,342,8);
floodfill(62,351,12);
setcolor(12);
for(i=0;i<10;i++){circle(62,337+i,1);}
for(i=0;i<2;i++)
{
setcolor(13);
line(130+i*140,380,150+i*140,360);
line(160+i*140,360,160+i*140,370);
line(160+i*140,360,170+i*140,360);
line(170+i*140,360,170+i*140,380);
line(170+i*140,380,180+i*140,380);
line(180+i*140,380,180+i*140,370);
for(j=0;j<6.29;j+=1e-3)
{
x=190+i*140+j/0.314;
y=370-10*sin(j);
putpixel(x,y,13);
}
setcolor(14);
for(j=0;j<3.5;j++)circle(110+j*30+i*140,390,3);
for(j=0;j<2.5;j++)
{
setcolor(4);
outtextxy(103+i*140,403+j*25,"<");
outtextxy(180+i*140,403+j*25,">");
setfillstyle(1,8);
bar(113+i*140,398+j*25,175+i*140,414+j*25);
}
setcolor(6);
outtextxy(195+i*140,401,"Hz");
outtextxy(195+i*140,426,"rad");
}
/*下划线*/
setcolor(4);
line(156,348,163,348);
line(296,348,303,348);
line(54,374,62,374);
line(54,409,62,409);
line(54,434,62,434);
line(54,459,62,459);
/*功能说明区*/
setcolor(13);
settextstyle(2,0,8);
outtextxy(370,330,"Int: ");
outtextxy(410,333,"S:Signal F: f");
outtextxy(410,349,"B: A: Max x|y");
{
char s[4];
s[0]=-24,s[1]=0;
outtextxy(466,349,s);
outtextxy(410,429,s);
outtextxy(434,429,s);
}
outtextxy(370,365,"Fun: ");
outtextxy(410,365,"underlined-key:quickkey");
outtextxy(410,381,"Blank: /32 Tab: /31");
outtextxy(410,397," < : - > : +");
outtextxy(370,413,"Sta: ");
outtextxy(410,413,"A1: A2:");
outtextxy(410,429," 2- 1 F2:F1");
outtextxy(410,450,"S-x: S-y:");
setfillstyle(1,7);
bar(452,445,482,465);
bar(540,445,570,465);
bar(440,410,490,423);
bar(540,410,590,423);
bar(452,427,490,440);
bar(540,427,590,440);
/*指示灯*/
lightswitch(178,344,8,4,1);
lightswitch(318,344,8,4,0);
lightswitch(85,370,5,5,1);
lightswitch(85,405,5,5,0);
lightswitch(85,430,5,5,0);
lightswitch(85,455,5,5,0);
lightswitch(110,390,3,14,1);
lightswitch(250,390,3,14,1);
for(i=0;i<2;i++)
for(j=1;j<4;j++)lightswitch(110+j*30+i*140,390,3,14,0);
smallimage(0,CH[i].infor[0]);
smallimage(1,CH[i].infor[0]);
}
void lightswitch(int x,int y,int r,int color,int key)/*开关灯*/
{
if (key==0)
{
setcolor(1);
circle(x,y,r);
setfillstyle(1,0);
floodfill(x,y,1);
setcolor(color);
circle(x,y,r);
return ;
}
setfillstyle(1,color);
floodfill(x,y,color);
}
void contrlcenter()/*控制中心*/
{ int i=0,j=0,j1,color;
float x,y,t1,t2,tx,ty,x0,t0;/*t1,t2为两信号周期,tx,ty是两信号时间*/
void makeloc(float *x,int i,float t);
void lightrec(int i,int j,int flag);
char key,s[10];
/*初始化工作*/
srand(time(NULL));
CH[1].infor[0]=CH[0].infor[0]=0;
CH[1].infor[1]=CH[0].infor[1]=1;
CH[1].infor[2]=CH[0].infor[2]=1;
CH[1].infor[3]=CH[0].infor[3]=50;
setcolor(4);
for(i=0;i<2;i++)
for(j=0;j<3;j++)
{
sprintf(s,"%.2f",CH[i].infor[j+1]);
outtextxy(120+i*140,405+j*24,s);
}
sprintf(s,"%.1f",CH[0].infor[3]);
outtextxy(445,413,s);
sprintf(s,"%.1f",CH[1].infor[3]);
outtextxy(545,413,s);
sprintf(s,"%.1f",CH[1].infor[2]-CH[0].infor[2]);
outtextxy(454,430,s);
sprintf(s,"%.1f",CH[1].infor[1]/CH[0].infor[1]);
outtextxy(542,430,s);
i=j=0;
while(1)
{
t1=1/CH[0].infor[1];t2=1/CH[1].infor[1];
x0=56,tx=ty=0;
while(!bioskey(1))
{
color=rand()%14+1;
makeloc(&x,0,tx);
makeloc(&y,1,ty);
t0=tx-((int)(tx/t1))*t1;
x0=t0/t1*160+56;
putpixel(x0,-40*x+105,color);
t0=ty-((int)(ty/t2))*t2;
x0=t0/t2*160+56;
putpixel(x0,-40*y+235,color);
x=415+CH[0].infor[3]*x;y=170+CH[1].infor[3]*y;
if (x>240&&y<280&&y>45)putpixel(x,y,color);
tx+=5e-4,ty+=5e-4;
if (tx>5*t1){tx=0;setfillstyle(1,0);bar(250,42,598,280);}
if (ty>5*t2){ty=0;setfillstyle(1,0);bar(250,42,598,280);}
}
key=bioskey(0);
switch(key)
{
case 9: lightswitch(85,locy[j],5,5,0);/*TAB 上下选择*/
j=(1+j)%4;
lightswitch(85,locy[j],5,5,1);
{ int temp;
if (!j) {lightrec(i,3,0);break;}
temp=1+(j+1)%3;
lightrec(i,temp,0);
temp=1+temp%3;
lightrec(i,temp,1);
}
break;
case 32: /*空格键左右选择*/
if (!j)
{
lightswitch(110+i*140+CH[i].infor[0]*30,390,3,14,0);
CH[i].infor[0]=((int) (1+CH[i].infor[0]))%4;
lightswitch(110+i*140+CH[i].infor[0]*30,390,3,14,1);
smallimage(i,CH[i].infor[0]);
break;
}
lightswitch(178+i*140,344,8,4,0);
lightrec(i,j,0);
i=(1+i)%2;
lightrec(i,j,1);
lightswitch(178+i*140,344,8,4,1);
break;
case '<': if (!j) break;
if (CH[i].infor[j]<6e-2) break;
switch(j)
{
case 1: CH[i].infor[j]-=5e-2;
setfillstyle(1,7);
bar(540,427,590,440);
setcolor(4);
sprintf(s,"%3.1f",CH[1].infor[1]/CH[0].infor[1]);
outtextxy(545,430,s);
break;
case 2: CH[i].infor[j]-=2e-2;
setfillstyle(1,7);
bar(452,427,490,440);
sprintf(s,"%.1f",(CH[1].infor[2]-CH[0].infor[2]));
setcolor(4);
outtextxy(454,430,s);
break;
case 3: CH[i].infor[j]-=1;
setfillstyle(1,7);
bar(440+i*100,410,490+i*100,423);
sprintf(s,"%.1f",CH[i].infor[3]);
setcolor(4);
outtextxy(445+i*100,413,s);
break;
}
setfillstyle(1,8);
bar(117+i*140,400+(j-1)*25,173+i*140,412+(j-1)*25);
sprintf(s,"%.2f",CH[i].infor[j]);
setcolor(4);
outtextxy(120+i*140,405+(j-1)*24,s);
break;
case '>': if (!j) break;
switch(j)
{
case 1: if (CH[i].infor[j]>10) break;
CH[i].infor[j]+=5e-2;
setfillstyle(1,7);
bar(540,427,590,440);
setcolor(7);
sprintf(s,"%3.1f",CH[1].infor[1]/CH[0].infor[1]);
setcolor(4);
outtextxy(545,430,s);
break;
case 2: if (CH[i].infor[j]>32)break;
CH[i].infor[j]+=2e-2;
setfillstyle(1,7);
bar(452,427,490,440);
sprintf(s,"%.1f",(CH[1].infor[2]-CH[0].infor[2]));
setcolor(4);
outtextxy(454,430,s);
break;
case 3: if (CH[i].infor[j]>100) break;
setfillstyle(1,7);
bar(440+i*100,410,490+i*100,423);
sprintf(s,"%.1f",CH[i].infor[3]);
setcolor(4);
outtextxy(445+i*100,413,s);
CH[i].infor[j]+=1;
break;
}
setfillstyle(1,8);
bar(117+i*140,400+(j-1)*25,173+i*140,412+(j-1)*25);
sprintf(s,"%.2f",CH[i].infor[j]);
setcolor(4);
outtextxy(120+i*140,405+(j-1)*24,s);
break;
case 'e':
case 'E': return;
case 'x':
case 'X': {if (!i) break;
lightswitch(318,344,8,4,0);
lightswitch(178,344,8,4,1);
i=0;
if (!j) break;
lightrec(1,j,0);
lightrec(0,j,1);
break;}
case 'y':
case 'Y': if (i) break;
lightswitch(178,344,8,4,0);
lightswitch(318,344,8,4,1);
i=1;
if (!j) break;
lightrec(0,j,0);
lightrec(1,j,1);
break;
default: lightswitch(85,locy[j],5,5,0);
if (j)
lightrec(i,j,0);
switch(key)
{
case 's':
case 'S': j=0;break;
case 'f':
case 'F': j=1;break;
case 'b':
case 'B': j=2;break;
case 'a':
case 'A': j=3;
}
if (j) lightrec(i,j,1);
lightswitch(85,locy[j],5,5,1);
break;
}
setfillstyle(1,0);
bar(50,65,228,168);
bar(50,190,228,298);
bar(250,42,598,280);
}
}
void lightrec(int i,int j,int flag)/*当前文本框加亮线或取消*/
{
if (!flag)setcolor(8);
else setcolor(12);
rectangle(113+i*140,398+(j-1)*25,175+i*140,414+(j-1)*25);
rectangle(114+i*140,399+(j-1)*25,174+i*140,413+(j-1)*25);
}
void makeloc(float *x,int i,float t)/*生成当前扫描点的位置*/
{
static int key;
static float t1;
key=CH[i].infor[0];
t1=t*CH[i].infor[1];
t1=t1-(int)(t1);
switch(key)/*判断是何种输入信号*/
{
case 0: *x=0; break;
case 1: *x=-1+t1*2; break;
case 2: *x=t1<0.5?1:-1;break;
case 3: *x=1*sin(t1*6.28+CH[i].infor[2]);break;
}
}
void smallimage(int i,int j)
{
float t,x,y;
setfillstyle(1,7);
bar(452+i*88,445,482+i*88,465);
setcolor(14);
switch(j)
{
case 0:break;/*无信号*/
case 1:line(457+i*88,464,477+i*88,446);break;/*线性*/
case 2:line(457+i*88,455,457+i*88,446);/*锯齿状信号*/
line(457+i*88,446,467+i*88,446);
line(467+i*88,446,467+i*88,464);
line(467+i*88,464,477+i*88,464);
line(477+i*88,464,477+i*88,455);
break;
case 3: for(t=0;t<6.29;t+=1e-3)/*正余弦信号*/
{
x=457+t/0.314+i*88;
y=455-10*sin(t);
putpixel(x,y,14);
}
}
}
我的网站 :http://www.tigerion.cn