#include "graphics.h" #include "math.h" #include "stdio.h" #include "dos.h" #include "conio.h" #include "stdlib.h" #include "stdarg.h" #define PI 3.14159265 main() { int driver=DETECT,mode; int i,j,e,g,N=15,R=90; int maxx,maxy; double x0=300,y0=240,x00=0,y00=0,x1,y1,x2,y2,q=(2*PI)/N,Vx=300,Vy=400,h=0.01; initgraph(&driver,&mode,""); maxx=getmaxx(); maxy=getmaxy(); settextstyle(1,0,5); outtextxy(150,10,"Knock-Ball!"); settextstyle(1,0,3); outtextxy(400,24,"---yanyan"); line(0,maxy-35,maxx,maxy-35); setbkcolor(1); line(0,55,maxx,55); outtextxy(200,maxy-30,"Press any key to exit..."); for(e=0;e<5000;e++) { while(!kbhit()) { x0+=Vx*h; y0+=Vy*h; Vy=Vy+300*h; if((x0-R)<=0||(x0+R)>=maxx) Vx=-Vx; if((y0-R)<=60||(y0+R)>=(maxy-40)) Vy=-Vy; x00=x0+Vx*h; y00=y0+Vy*h; setcolor(YELLOW); setlinestyle(0,5,5); setcolor(1); circle(x0,y0,R); for(i=0;i<N;i++) { x1=R*cos(i*q)+x0; y1=R*sin(i*q)+y0; for(j=0;j<N;j++) { x2=R*cos(j*q)+x0; y2=R*sin(j*q)+y0; line(x1,y1,x2,y2); } } setcolor(RED); circle(x00,y00,R); for(i=0;i<N;i++) { x1=R*cos(i*q)+x00; y1=R*sin(i*q)+y00; for(j=0;j<N;j++) { x2=R*cos(j*q)+x00; y2=R*sin(j*q)+y00; line(x1,y1,x2,y2); } } } } closegraph(); }