//
// GravitySim.java (200810094) FB
import java.applet.Applet;
import java.awt.*;
import java.awt.image.*;
public class GravitySim extends Applet
{
Image img;
int wd,ht,pix[],alpha;
public void init()
{
wd=getSize().width;ht=getSize().height;alpha=255;
pix=new int[wd*ht];
gr();
img=createImage(new MemoryImageSource(wd,ht,pix,0,wd));
}
public void paint(Graphics g)
{
g.drawImage(img,0,0,this);
// Refresh Periodically
long t=System.currentTimeMillis();
while((System.currentTimeMillis()-t)<5000) {;}
// delete the old graph
for(int i=0;i0)
double dmin = 40.0; // min allowed distance between objects
int mx, my, k, j;mx = wd-1;my = ht-1;
double ang, v, dx, dy, d, a, ax, ay;
double x[], y[], xnew[], ynew[], m[], vx[], vy[];
int rd[], gr[], bl[];
m=new double[n];x=new double[n];y=new double[n];
xnew=new double[n];ynew=new double[n];
vx=new double[n];vy=new double[n];
rd=new int[n];gr=new int[n];bl=new int[n];
double Sx, Sy, Svx, Svy, Sm;
Sx = Sy = Svx = Svy = Sm = 0;
for(k=0;kmx || y[k]<0 || y[k]>my))
{
pix[wd*(int)y[k]+(int)x[k]]=(alpha<<24)|(rd[k]<<16)|(gr[k]<<8)|bl[k];
fl=true;
}
}
}
while(fl);
}
}