<commit_before>import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
import java.util.ArrayList;


public class Simstate {

	private ArrayList<Planet> thePlanets;
	private ArrayList<double[][]> history;
	private double historyLength = 0.0;
	private int tickCount = 0;
	private int historyDetail = 1;
	private boolean historyGradient = false;
	private int algorithm = 0;
	
	public Simstate(){
		thePlanets = new ArrayList<Planet>();
		history = new ArrayList<double[][]>();
	}
	
	public void render(Graphics2D g2d, int xOffset, int yOffset, double scale) {
		//for every step
		g2d.setStroke(new BasicStroke(2, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); //setting stroke of lines
		for(int i = 1; i < history.size(); i++){
			double[][]t = history.get(i);
			double[][]tOld = history.get(i-1);
			//drawing lines between past positions of planets
			for (int j = 0; j < t.length; j++){
				if(historyGradient){ //gradient paths
					//mixing colors for paths
					Color p = thePlanets.get(j).getColor(); //planet color
					Color b = Sim.bgColor; //bg color
					//gradient function: -(2x)^2+1 -> gradient from c1 to c2 where c1 is full at 0 and c2 is full at 1/2 the length of the array of points
					double mix = -1.0*(Math.pow(2.0*(double)(history.size()-i)/(double)history.size(), 2))+1.0; 
					if(mix < 0) mix = 0; 
					double mix2 = 1.0-mix;
					//getting rgb values of the two colors
					double r1 = p.getRed();
					double g1 = p.getGreen();
					double b1 = p.getBlue();				
					double r2 = b.getRed();
					double g2 = b.getGreen();
					double b2 = b.getBlue();
					//mixing the two based on the the gradient from earlier
					double rf = Math.sqrt(r1*r1*mix + r2*r2*mix2);
					double gf = Math.sqrt(g1*g1*mix + g2*g2*mix2);
					double bf = Math.sqrt(b1*b1*mix + b2*b2*mix2);
					Color fc = new Color((int)rf, (int)gf, (int)bf);
					//setting the color
					g2d.setColor(fc);
				}else{ //non gradient paths
					//setting the color
					g2d.setColor(thePlanets.get(j).getColor());
				}
				//drawing lines from point to point				
				g2d.drawLine(	(int)(tOld[j][0]*scale)+xOffset,
								(int)(tOld[j][1]*scale)+yOffset,
								(int)(t[j][0]*scale)+xOffset,
								(int)(t[j][1]*scale)+yOffset
						);
			}
		}
		//rendering planets
		for(Planet p : thePlanets){
			p.render(g2d, xOffset, yOffset, scale);
		}
		//rendering algorithm type
		g2d.setColor(Sim.bgColorI);
		switch (algorithm){
			case 0:
				g2d.drawString("Euler", 20, 40);
				break;
			case 1:
				g2d.drawString("Verlet", 20, 40);
				break;
		}
	}
	
	public void tick(double t) { //updates planets	
		switch (algorithm){
			case 0:
				tickEuler(t);
				break;
			case 1:
				tickVerlet(t);
				break;
			case 2:
				tickRK4(t);
				break;
			default:
				tickEuler(t);
				break;
		}
		tickCount++;
		if (tickCount % historyDetail == 0){
			if(historyLength == -1 || history.size() < historyLength/(t*(double)historyDetail)){
				history.add(getPlanetPositions());
			}else if(historyLength == 0){
				while(history.size() > 0){
					history.remove(0);
				}
			}else{
				while(history.size() > historyLength/(t*(double)historyDetail)){
					history.remove(0);
				}
				history.add(getPlanetPositions());
			}
		}
	}
	
	public void tickEuler(double t){
		for(Planet p: thePlanets) p.updateAccelerationEuler();
		for(Planet p: thePlanets) p.updatePositionEuler(t);
		for(Planet p: thePlanets) p.updateVelocityEuler(t);	
	}
	
	public void tickVerlet(double t){
		for(Planet p: thePlanets) p.updateAccelerationVerlet();
		for(Planet p: thePlanets) p.updatePositionVerlet(t);
		for(Planet p: thePlanets) p.updateAccelerationVerlet();
		for(Planet p: thePlanets) p.updateVelocityVerlet(t);
	}
	
	public void tickRK4(double dt){
		//initialising
		State state = new State();<commit_msg>Fixed Euler algorithm<commit_after>import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
import java.util.ArrayList;


public class Simstate {

	private ArrayList<Planet> thePlanets;
	private ArrayList<double[][]> history;
	private double historyLength = 0.0;
	private int tickCount = 0;
	private int historyDetail = 1;
	private boolean historyGradient = false;
	private int algorithm = 0;
	
	public Simstate(){
		thePlanets = new ArrayList<Planet>();
		history = new ArrayList<double[][]>();
	}
	
	public void render(Graphics2D g2d, int xOffset, int yOffset, double scale) {
		//for every step
		g2d.setStroke(new BasicStroke(2, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); //setting stroke of lines
		for(int i = 1; i < history.size(); i++){
			double[][]t = history.get(i);
			double[][]tOld = history.get(i-1);
			//drawing lines between past positions of planets
			for (int j = 0; j < t.length; j++){
				if(historyGradient){ //gradient paths
					//mixing colors for paths
					Color p = thePlanets.get(j).getColor(); //planet color
					Color b = Sim.bgColor; //bg color
					//gradient function: -(2x)^2+1 -> gradient from c1 to c2 where c1 is full at 0 and c2 is full at 1/2 the length of the array of points
					double mix = -1.0*(Math.pow(2.0*(double)(history.size()-i)/(double)history.size(), 2))+1.0; 
					if(mix < 0) mix = 0; 
					double mix2 = 1.0-mix;
					//getting rgb values of the two colors
					double r1 = p.getRed();
					double g1 = p.getGreen();
					double b1 = p.getBlue();				
					double r2 = b.getRed();
					double g2 = b.getGreen();
					double b2 = b.getBlue();
					//mixing the two based on the the gradient from earlier
					double rf = Math.sqrt(r1*r1*mix + r2*r2*mix2);
					double gf = Math.sqrt(g1*g1*mix + g2*g2*mix2);
					double bf = Math.sqrt(b1*b1*mix + b2*b2*mix2);
					Color fc = new Color((int)rf, (int)gf, (int)bf);
					//setting the color
					g2d.setColor(fc);
				}else{ //non gradient paths
					//setting the color
					g2d.setColor(thePlanets.get(j).getColor());
				}
				//drawing lines from point to point				
				g2d.drawLine(	(int)(tOld[j][0]*scale)+xOffset,
								(int)(tOld[j][1]*scale)+yOffset,
								(int)(t[j][0]*scale)+xOffset,
								(int)(t[j][1]*scale)+yOffset
						);
			}
		}
		//rendering planets
		for(Planet p : thePlanets){
			p.render(g2d, xOffset, yOffset, scale);
		}
		//rendering algorithm type
		g2d.setColor(Sim.bgColorI);
		switch (algorithm){
			case 0:
				g2d.drawString("Euler", 20, 40);
				break;
			case 1:
				g2d.drawString("Verlet", 20, 40);
				break;
		}
	}
	
	public void tick(double t) { //updates planets	
		switch (algorithm){
			case 0:
				tickEuler(t);
				break;
			case 1:
				tickVerlet(t);
				break;
			case 2:
				tickRK4(t);
				break;
			default:
				tickEuler(t);
				break;
		}
		tickCount++;
		if (tickCount % historyDetail == 0){
			if(historyLength == -1 || history.size() < historyLength/(t*(double)historyDetail)){
				history.add(getPlanetPositions());
			}else if(historyLength == 0){
				while(history.size() > 0){
					history.remove(0);
				}
			}else{
				while(history.size() > historyLength/(t*(double)historyDetail)){
					history.remove(0);
				}
				history.add(getPlanetPositions());
			}
		}
	}
	
	public void tickEuler(double t){
		for(Planet p: thePlanets) p.updateAccelerationEuler();
		for(Planet p: thePlanets) p.updateVelocityEuler(t);	
		for(Planet p: thePlanets) p.updatePositionEuler(t);

	}
	
	public void tickVerlet(double t){
		for(Planet p: thePlanets) p.updateAccelerationVerlet();
		for(Planet p: thePlanets) p.updatePositionVerlet(t);
		for(Planet p: thePlanets) p.updateAccelerationVerlet();
		for(Planet p: thePlanets) p.updateVelocityVerlet(t);
	}
	
	public void tickRK4(double dt){
		//initialising
		State state = new State();
{'fraction_non_alphanumeric': 0.14729393264316604, 'fraction_numerical': 0.023063818634517102, 'mean_word_length': 3.24, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1500850', 'n_tokens_mistral': 3351, 'n_tokens_neox': 2716, 'n_words': 675}