#config clearmemory //general initialization #config complexoff #config gl //3D-graphics initialisation #config axesoff #config labelsoff #config rasteroff A[0]=3.34; //position first electric charge A[1]=3; A[2]=3; A[3]=6; //value B[0]=-3; //position of second electric charge B[1]=-3; B[2]=-3; B[3]=-6; //value L=0; M=0; N="0"; glstartlist; //display list for the charge ball glbegin(polygon); glpoint(-1,0,0); glpoint(-0.707,0.707,0); glpoint(0,1,0); glpoint(0.707,0.707,0); glpoint(1,0,0); glpoint(0.707,-0.707,0); glpoint(0,-1,0); glpoint(-0.707,-0.707,0); glend; glbegin(polygon); glpoint(-1,0,0); glpoint(-0.707,0,0.707); glpoint(0,0,1); glpoint(0.707,0,0.707); glpoint(1,0,0); glpoint(0.707,0,-0.707); glpoint(0,0,-1); glpoint(-0.707,0,-0.707); glend; glbegin(polygon); glpoint(0,-1,0); glpoint(0,-0.707,0.707); glpoint(0,0,1); glpoint(0,0.707,0.707); glpoint(0,1,0); glpoint(0,0.707,-0.707); glpoint(0,0,-1); glpoint(0,-0.707,-0.707); glend; P=glendlist; while(1) { glclear; //clear scene glbegin(lines); //calculate field for(C[0]=-9; C[0]<11; C[0]=C[0]+3) { for(C[1]=-9; C[1]<11; C[1]=C[1]+3) { for(C[2]=-10; C[2]<11; C[2]=C[2]+2) { D[0]=A[0]; D[1]=A[1]; D[2]=A[2]; E[0]=C[0]; E[1]=C[1]; E[2]=C[2]; F=E[]-D[]; G=sqrt(F[0]^2+F[1]^2+F[2]^2); F=F[]*A[3]; D[0]=B[0]; D[1]=B[1]; D[2]=B[2]; H=E[]-D[]; K=sqrt(H[0]^2+H[1]^2+H[2]^2); H=H[]*B[3]; E[0]=A[0]; E[1]=A[1]; E[2]=A[2]; J=(1/G^2)*F[]+(1/K^2)*H[]; I=sqrt(J[0]^2+J[1]^2+J[2]^2); J=J[]*(3/I); glcolor(I*100,0,255-I*100); glpoint(C[0]-J[0]/2,C[1]-J[1]/2,C[2]-J[2]/2); glpoint(C[0]+J[0]/2,C[1]+J[1]/2,C[2]+J[2]/2); } } } glend; glstring(10,20,"Charge1"); //draw information text glstring(100,20,A[0]); glstring(150,20,A[1]); glstring(200,20,A[2]); glstring(250,20,A[3]); if(L<4) glstring(100+L*50,20,"__"); glstring(10,35,"Charge2"); glstring(100,35,B[0]); glstring(150,35,B[1]); glstring(200,35,B[2]); glstring(250,35,B[3]); if(L>=4) glstring(100+(L-4)*50,35,"__"); glstring(10,50,N); glloadidentity; if(A[3]>0) //draw charge balls glcolor(255,0,0); else glcolor(0,0,255); glmove(A[0],A[1],A[2]); glscale(0.5,0.5,0.5); glcalllist(P); glrotate(45,1,1,1); glcalllist(P); glloadidentity; if(B[3]>0) glcolor(255,0,0); else glcolor(0,0,255); glmove(B[0],B[1],B[2]); glscale(0.5,0.5,0.5); glcalllist(P); glrotate(45,1,1,1); glcalllist(P); glshow; O=getkey; //recive keyboard input N[M]=O[0]; if(N[M]==13) //process keyboard input { N[M]=0; if(M>0) { if(L<4) A[L]=(float)N; else B[L-4]=(float)N; } L=L+1; if(L>7) L=0; M=0; N="0"; } else M=M+1; }