这个程序实现平抛运动的轨迹
大家有什么好的修改意见,欢迎给我留言
源程序为
#include "conio.h" #include"graphics.h" void f(int i) {int j; for(j=0;j<i;j++) delay(25000);}
void rest() {int i; for(i=5;i>0;i--) {textcolor(8+i);if(i==2) textcolor(14); gotoxy(30,23-i); cprintf("rest:%d seconds",i);f(15);}}
void welcome() {int i,j; cleardevice(); setbkcolor(0); for(j=0;j<22;j++) { setfillstyle(8,3); bar(30*j,0,15+30*j,478);bar(0,30*j,655,15+30*j); }
for(i=1;i<60;i++) {textcolor(4);gotoxy(i+7,11);cprintf("Welcome"); gotoxy(67-i,15);cprintf("Welcome"); f(2); textcolor(0);gotoxy(i+7,11);cprintf("Welcome"); gotoxy(67-i,15);cprintf("Welcome");} for(j=0;j<22;j++) {setfillstyle(8,3);bar(30*j,0,15+30*j,478);bar(0,30*j,655,15+30*j);} textcolor(4); gotoxy(29,13);cprintf("***** Welcome *****");f(25); textcolor(2); gotoxy(30,16);cprintf("Start in 5 seconds");f(15); rest();}
void h() {int i=0,j,k,x,y;char d[30]="Once again? ", b[30]="If you want to once again,", c[30]="please put \"y\", else put \"n\"."; float g,v;
loop:setbkcolor(11); if(i) {cleardevice(); gotoxy(5,6); textcolor(4); cprintf("Error,input g and Vo again.");f(10);} cleardevice(); textcolor(12); gotoxy(5,7); cprintf("Please input g and V"); gotoxy(10,8);cprintf("g= m/(s*s):"); textcolor(1);gotoxy(13,8); cscanf("%f",&g); if((int)100*g>1050) {i=1;goto loop;} textcolor(12);gotoxy(10,9);cprintf("Vo= m/s"); textcolor(1);gotoxy(13,9);cscanf("%f",&v); if((int)1000*v>2600){i=1;goto loop;}
cleardevice(); setbkcolor(11); moveto(31,11); setcolor(2); setlinestyle(0,0,3); line(31,11,500,11);outtextxy(500,2,"x(cm)"); line(31,11,31,450);outtextxy(2,451,"y(cm)"); setcolor(4); setlinestyle(0,0,3); moveto(31,11); for(i=2;i<=21;i++) { lineto(8*i*v+30,0.1*g*i*i+10); } setcolor(5); setlinestyle(1,0,1); for(j=4;j<=20;j=j+2) {moveto(8*j*v+30,0.1*g*j*j+10); line(8*j*v+30,0.1*g*j*j+10,8*j*v+30,1+10); line(8*j*v+30,0.1*g*j*j+10,1+30,0.1*g*j*j+10); f(2);} setlinestyle(1,0,3); setcolor(6); for(i=1;i<=7;i++) {if(i<=5) circle(31,10+80*i,1); circle(30+64*i,11,1);} moveto(24,5);outtext("0"); moveto(87,3);outtext("40");moveto(147,3);outtext("80"); moveto(212,3);outtext("120");moveto(278,3);outtext("160"); moveto(340,3);outtext("200");moveto(406,3);outtext("240"); moveto(470,3);outtext("280"); f(8); moveto(3,90);outtext("100");moveto(3,170);outtext("200"); moveto(3,250);outtext("300");moveto(3,330);outtext("400"); moveto(3,410);outtext("500");
setlinestyle(0,0,1);f(6); setfillstyle(1,11);bar(355,60,600,250); textcolor(1); gotoxy(45,5);cprintf("g=%5.3fcm/(s*s)",g);f(6); gotoxy(45,6);cprintf("Vo=%5.3fm/s",v);f(4); rectangle(350,100,600,250); for(i=0;i<240;i=i+40) {line(350+i,100,350+i,250); f(5);} line(600,100,600,250); for(i=0;i<=100;i=i+50) {line(350,100+i,600,100+i); f(5);} line(350,250,600,250); moveto(350,115);outtext(" t"); moveto(350,125);outtext("(0.1s)"); moveto(400,120);outtext(" 2 4 6 8 10");f(12); moveto(350,170);outtext("x(cm)"); moveto(350,215);outtext("y(cm)"); textcolor(1); gotoxy(50,11);for(i=2;i<=10;i+=2) {if((int)v>=1) cprintf("%5.1f",10*i*v); else cprintf("%5.2f",10*i*v);} gotoxy(50,14);for(i=2;i<=10;i+=2) {if((int)g>=2) cprintf("%5.1f",0.5*g*i*i); else cprintf("%5.2f",0.5*g*i*i); } for(i=0;i<240;i+=40) line(350+i,100,350+i,250); textcolor(9); gotoxy(45,19);for(i=0;i<26;i++) {cprintf("%c",b[i]);f(1);} gotoxy(45,20);for(i=0;i<29;i++) {cprintf("%c",c[i]);f(1);} gotoxy(45,21);for(i=0;i<12;i++) {cprintf("%c",d[i]);f(1);} }
main() {int a[10]; int driver=0,mode,i,j,k,x,y; initgraph(&driver,&mode,""); directvideo=0; welcome(); h(); for(k=0;;k++) { gets(a); if(a[0]=='y'||a[0]=='Y') h(); else break; } cleardevice(); setbkcolor(3); setcolor(6); setfillstyle(11,4);floodfill(10,10,4);bar(0,0,655,478); for(i=0;i<655;i+=5)line(i,0,i,478); for(i=0;i<478;i+=5)line(0,i,655,i); textcolor(1);gotoxy(30,16);cprintf("****B*y*e****"); f(12); rest(); closegraph();}