Hello all,
In my sketch, I have a bunch of balls bouncing around. I am saving the X, Y values of each ball, and the XSpeed, and YSpeed value of each ball every time draw() runs.
I use the following code :
PrintWriter hist1;
PrintWriter hist2;
hist1 = createWriter("spatial_density.txt");
hist2 = createWriter("Velocity_distribution.txt");
void draw(){
background(255);
for (int i = 0; i < elec.length; i++){
elec[i].update(elec);
elec[i].move();
elec[i].bounce();
hist1.println(nf(elec[i].getX(),0,2) +","+ nf(elec[i].getY(),0,2) );
hist2.println(nf(elec[i].getDX(),0,2) +","+ nf(elec[i].getDY(),0,2) );
}
hist1.println("------------ F " + j);
hist2.println("-------------F " + j);
j+=1;
At first I thought I would end the program after j reaches a threshold value, however even that produces uneven data in the text files: i.e., for example, spatial_density file will have, say, data up to j = 800, and the velocity_distribution, only 600.
I also used the time module to exit the program after a certain time has elapsed, but that had the same results.
My canvas is 700*600 big and the balls are 2 pixels wide.
I would want the data files to be of even order ie : x,y and xpeed, yspeed value of all balls upto j = same value.
What seems to be the problem?