This is a pretty simple system, just a bunch of masses attached by springs. One of the masses has some velocity, and so it pulls the other masses with it (the speed at which they move of course is dependent on their mass and the spring constant of the spring attaching them). One thing introduced in this model was that one of the balls has a lot more mass than the others, so you'll see it takes a while for it to start to move, that's because it takes a lot of force to cause the mass to accelerate, so the distance between the two masses must be really big before it'll start to accelerate.

read more

Mass.java

			
public class Mass {
	
	public double startingxJerk; 
	public double startingyJerk;
	public double xJerk;
	public double yJerk;
	public double startingxAcceleration;
	public double startingyAcceleration;
	public double startingyVelocity;
	public double startingxVelocity;
	public double xAcceleration;
	public double yAcceleration;
	public double xVelocity;
	public double yVelocity;
	public double xPosition;
	public double yPosition;
	public double currentTime;
	public boolean underInfluence;
	public double mass;
	public Spring spring;
	public int yincrementer;
	public int xincrementer;
	public boolean collision;
	public double energyLoss = .1;
	

	public Mass(double startingxJerk, double startingyJerk, double startingxAcceleration, double startingyAcceleration,double startingxVelocity, double startingyVelocity,double mass,
			double xPosition, double yPosition, double currentTime,boolean underInfluence) {
		
		this.startingxAcceleration = startingxAcceleration;
		this.startingyAcceleration = startingyAcceleration;
		this.startingyVelocity = startingyVelocity;
		this.startingxVelocity = startingxVelocity;
		this.xPosition = xPosition;
		this.yPosition = yPosition;
		this.currentTime = currentTime;
		this.underInfluence = underInfluence;
		this.mass = mass;
		this.yVelocity = startingyVelocity;
		this.xVelocity = startingxVelocity;
	}	
	
public void update(){
			
	if(this.underInfluence){
		this.xAcceleration=(((-spring.Xtension)+this.startingxAcceleration))/this.mass;
		//this.yAcceleration=(((spring.Ytension)+this.startingyAcceleration))/this.mass;
	}
	if(!this.underInfluence){
		this.xAcceleration=((spring.Xtension)+this.startingxAcceleration)/this.mass;
		//this.yAcceleration=((-spring.Ytension)+this.startingyAcceleration)/this.mass;
	}
	
	//if(!this.underInfluence&&this.xVelocity>=10){
		//this.xAcceleration=0;
		//this.xVelocity=1;
		
	//}
	
	
	yincrementer--;
	xincrementer--;
	
	
	
	
	this.xVelocity += this.xAcceleration;
	this.yVelocity += this.yAcceleration;
	
	
	this.xPosition=this.xPosition+(this.xVelocity);
	this.yPosition=this.yPosition+(this.yVelocity);
	
		
	
}
	
	
}

massOne.java

			
public class massOne {


	public double xacceleration = 0; 
	public double xvelocity = 0; 
	public double xposition = 90; 
	public double yposition = 60; 
	public double currentTime = 0;


	public void update(){

		this.xvelocity += this.xacceleration; 

		this.xposition=this.xposition+(this.xvelocity);


	}



}

massTwo.java

			
public class massTwo {

	public int xacceleration = 0; 
	public double xvelocity = 0; 
	public double xposition = 90; 
	public double yposition = 200; 
	public double currentTime = 0;
	
	massOne massOne = new massOne();
	//spring spring = new spring();
	
	public void update(){
		
		
		
		this.xvelocity += this.xacceleration; 
		
		this.xposition=this.xposition+(this.xvelocity);
		
		
	}
	
}

Spring.java

			
public class Spring {
	private Mass massOne;
	private Mass massTwo;
	public double startingX = 0; 
	public double startingY = 0; 
	public double endingX = 0; 
	public double endingY = 0;
	public double tension = 0; 
	public double Xtension = 0; 
	public double Ytension = 0; 
	public double currentTime = 0;
	public double gravity = 0;
	public double springConstant = 1; 
	public double scaler = .01;
	public double angle = 0;

	public Spring(Mass massOne, Mass massTwo) {
		this.massOne = massOne;
		this.massTwo = massTwo;
		massOne.spring = this;
		massTwo.spring = this;
		//this.Ytension = massTwo.mass*gravity;
	}

public void update(){
			
		
		this.startingX = massOne.xPosition; 
		this.startingY = massOne.yPosition; 
		this.endingX = massTwo.xPosition; 
		this.endingY = massTwo.yPosition;
		//this.tension = scaler*springConstant*Math.hypot((massOne.xPosition-massTwo.xPosition), (massOne.yPosition-massTwo.yPosition)); //in newtons/pixel
		this.Xtension = scaler*springConstant*Math.abs(massOne.xPosition-massTwo.xPosition);
		this.Ytension = -1*scaler*springConstant*(massOne.yPosition-massTwo.yPosition);
		//System.out.println(this.Ytension);
		
		
		
	
}

}

SpringController.java

			
public class SpringController {
	
	Mass allMasses[];
	Spring allSprings[];
	
	public SpringController(int numberOfMasses){
		this.allMasses= new Mass[10];
		this.allSprings=new Spring[10];
		
		for(int i=0;i<numberOfMasses;i++){
			
			allMasses[i]=new Mass(0,0,0,0,0,0, 2, 500, 100+20*i, 0,true);
			
			if(i>0){
				 allSprings[i-1] = new Spring(allMasses[i-1], allMasses[i]);
			}
			
		}
		
		
	}
	
	/*
	
	Mass ex = new Mass(0,0,0,0,.1,0, 2, 50, 50, 0,false);
	Mass exSquared = new Mass(0,0,.2,0,0,0, 2, 100, 200, 0,true);
	Mass exCubed = new Mass(6,0,0,0,3,6, 10, 90, 200, 0,true); 
	//Mass exQuarted = new Mass(0,0,3,6, 10, 90, 200, 0,true);
	Spring springexToexSquared = new Spring(ex, exSquared);
	
	 */
	//double startingxJerk, double startingyJerk, double startingxAcceleration, double startingyAcceleration,double startingxVelocity, double startingyVelocity,double mass,double xPosition, double yPosition, double currentTime,boolean underInfluence

}

system.java

			
import java.awt.Graphics;
import java.awt.Rectangle;


public class system extends java.applet.Applet implements Runnable {
	    int frame;
	    int delay;
	    int increment=1;
	    int numberOfPoints=0;
	    int numberOfMasses = 10;
	    int xycoords[][]= new int [2][100000];
	    double endpoints[][] = new double[2][100000];
	    int xycoords2[][]= new int [2][100000];
	    int angles[]= new int [10000];
	    Thread animator;
	    

	    /**
	     * Initialize the applet and compute the delay between frames.
	     */
	    public void init() {
		String str = getParameter("fps");
		int fps = (str != null) ? Integer.parseInt(str) : 50;
		delay = (fps > 0) ? (1000 / fps) : 100;
	    }

	    /**
	     * This method is called when the applet becomes visible on
	     * the screen. Create a thread and start it.
	     */
	    public void start() {
		animator = new Thread(this);
		animator.start();
	    }

	    /**
	     * This method is called by the thread that was created in
	     * the start method. It does the main animation.
	     */
	    public void run() {
	    	 
		while (Thread.currentThread() == animator) {
		    // Display the next frame of animation.
			increment++;
		    repaint();
		    
		    // Delay for a while
		    try {
			Thread.sleep(delay);
		    } catch (InterruptedException e) {
			break;
		    }

		    // Advance the frame
		    frame++;
		}
	    }

	    /**
	     * This method is called when the applet is no longer
	     * visible. Set the animator variable to null so that the
	     * thread will exit before displaying the next frame.
	     */
	    public void stop() {
		animator = null;
	    }
	    

	    /**
	     * Paint a frame of animation.
	     */
	   
	    SpringController chain = new SpringController(numberOfMasses);
	    
	    
	  boolean collision=false;
	  boolean drawn=false;
	  int constantincrementor=0;
	  
		public void paint(Graphics g) {
			// try {
			// Thread.sleep(500);
			// } catch (InterruptedException e) {
			// TODO Auto-generated catch block
			// e.printStackTrace();
			// }
			//hey.setA(500);
			//hey.setR(10);
			//hey.setV(2);

			if (!drawn) {
				//hey.collision1 = true;
				drawn = true;
				this.setSize(1920, 1200);
				chain.allMasses[9].xVelocity=2;
				chain.allMasses[5].mass=100;
				

			}
			System.out.println(chain.allMasses[9].xVelocity);
			
			//g.drawRect(hey.abound, hey.bbound, hey.cbound, hey.dbound);//I just realized that my points are the center of the circle
			
			
			
			//massOne.currentTime=this.increment;
			
			
			
			//if(Math.abs(objects.massTwo.xPosition-objects.massOne.xPosition)<=10&&Math.abs(objects.massTwo.yPosition-objects.massOne.yPosition)<=10){
				
			//}
			
			for(int i=0; i<numberOfMasses; i++){
				chain.allMasses[i].update();
				if(i>0){
					chain.allSprings[i-1].update();
				}
			}
			
		
			
			/**
			xycoords[0][numberOfPoints]=(int) objects.ex.xPosition;
			xycoords[1][numberOfPoints]=(int) objects.ex.yPosition;
			xycoords2[0][numberOfPoints]=(int) objects.exSquared.xPosition;
			xycoords2[1][numberOfPoints]=(int) objects.exSquared.yPosition;
		
			
			numberOfPoints++;
			
			if(numberOfPoints>1){
			for(int i=0; i<numberOfPoints-1;i++){
				
			g.drawLine(xycoords[0][i], xycoords[1][i], xycoords[0][i+1], xycoords[1][i+1]);
			g.drawLine(xycoords2[0][i], xycoords2[1][i], xycoords2[0][i+1], xycoords2[1][i+1]);
			
			
			}
			
			}
				*/
			
			
			//collision = hey.xymove(increment);
			
			if (collision) {
				increment = 1;
				collision = false;
				//angles[constantincrementor]=hey.theta;
				constantincrementor++;
			}

			
			for(int i=0; i<numberOfMasses; i++){
				chain.allMasses[i].update();
				g.fillOval((int) chain.allMasses[i].xPosition, (int) chain.allMasses[i].yPosition, 10, 10);
				if(i>0){
					g.drawLine((int)chain.allSprings[i-1].startingX +5, (int)chain.allSprings[i-1].startingY +5, (int)chain.allSprings[i-1].endingX +5, (int)chain.allSprings[i-1].endingY+5);
					chain.allSprings[i-1].update();
				}
			}
			
			
			
			//g.drawLine((int)objects.massOne.xPosition +10, (int)objects.massOne.yPosition +10, (int)objects.massOne.xPosition+10+ (10)*(int)objects.massOne.xVelocity, (int)objects.massOne.yPosition +10+ (10)*(int)objects.massOne.yVelocity);
		}		

			
	}