📄 simu.bak
字号:
#include <stdio.h>
#include <graphics.h>
#include <math.h>
char buf[100];
char filename[200];
int down_flag= 0;
float x_c,y_c;
main()
{
FILE *fpe;
int gdriver = DETECT, gmode=18, errorcode;
int ret,i,j,k,x1,y1,x2,y2;
float minx,miny,maxx,maxy;
float curx,cury,x,y,oldx,oldy;
// printf("Please Input Your File Name To Simu:\n");
// scanf("%s",filename);
x_c = y_c = 0;
strcpy(filename,"c:\\jgs\\test.23");
fpe = fopen(filename,"rb");
ret = get_a_line(fpe);
minx = miny = maxx = maxy = curx = cury = 0;
while (ret != -1){
if ((buf[0] == 'P')||(buf[0] == 'B')){
x = atof(&(buf[1]));
i = 1;
while (buf[i++] != ' ');
y = atof(&(buf[i]));
curx += x;
cury += y;
if (minx > curx)
minx = curx;
if (maxx < curx)
maxx = curx;
if (miny > cury)
miny = cury;
if (maxy < cury)
maxy = cury;
}
ret = get_a_line(fpe);
}
fclose(fpe);
fpe = fopen(filename,"rb");
ret = get_a_line(fpe);
curx = cury = oldx = oldy = 0;
initgraph(&gdriver, &gmode, "c:\\jgs");
setcolor(WHITE);
j = 0;
k = 0;
while (ret != -1){
if ((buf[0] == 'P')||(buf[0] == 'B')){
x = atof(&(buf[1]));
i = 1;
while (buf[i++] != ' ');
y = atof(&(buf[i]));
curx += x;
cury += y;
x_c += x;
y_c += y;
if (fabs(maxx-minx) > fabs(maxy-miny)){
x1 = 480.0*(oldx-(maxx+minx)/2.0)/(maxx-minx) + 240;
y1 = 240 - 480.0*(oldy-(maxy+miny)/2.0)/(maxx-minx);
x2 = 480.0*(curx-(maxx+minx)/2.0)/(maxx-minx) + 240;
y2 = 240 - 480.0*(cury-(maxy+miny)/2.0)/(maxx-minx);
}
else{
x1 = 480.0*(oldx-(maxx+minx)/2.0)/(maxy-miny) + 240;
y1 = 240 - 480.0*(oldy-(maxy+miny)/2.0)/(maxy-miny);
x2 = 480.0*(curx-(maxx+minx)/2.0)/(maxy-miny) + 240;
y2 = 240 - 480.0*(cury-(maxy+miny)/2.0)/(maxy-miny);
}
if (down_flag == 0){
setcolor(GREEN);
line(x1,y1,x2,y2);
}
else{
setcolor(WHITE);
line(x1,y1,x2,y2);
}
oldx = curx;
oldy = cury;
}
if (strcmp(buf,"O 32 63") == 0){
down_flag = 1;
}
if (strcmp(buf,"O 0 63") == 0){
down_flag = 0;
}
ret = get_a_line(fpe);
j ++;
}
fclose(fpe);
printf("%f %f\n",x_c,y_c);
getch();
closegraph();
}
get_a_line(FILE *fpe)
{
int i,ch;
ch = fgetc(fpe);
if (ch == EOF)
return -1;
i = 0;
while ((ch != 13)&&(ch != 10)&&(ch != EOF)){
buf[i++] = ch;
ch = fgetc(fpe);
}
buf[i] = 0;
if (ch == EOF)
return -1;
fgetc(fpe);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -