We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › lines with a for loop.
Page Index Toggle Pages: 1
lines with a for loop. (Read 224 times)
lines with a for loop.
Sep 25th, 2006, 9:11pm
 
Hi again. I'm trying to find a way to draw lines within a for loop but i'm having a problem doing this none of my lines show up can some one take a look at the code and let me know whats going on. I've noted the part where i'm having the problem.

import traer.physics.*;

ParticleSystem physics;
Particle[][] particles;
Spring[][] springs;
int gridSize = 20;

void setup()
{
 size(800, 800);
 smooth();
 fill(0);
 framerate(60);
 
   physics = new ParticleSystem(0, 0,20,0.5);
 
 particles = new Particle[gridSize][gridSize];
 springs = new Spring[gridSize][gridSize];
 
 float gridStepX = (float) ((width / 2) / gridSize);
 float gridStepY = (float) ((height / 2) / gridSize);
 
 for (int i = 0; i < gridSize; i++)
 {
   for (int j = 0; j < gridSize; j++)
   {
//Spring makeSpring( Particle a, Particle b, float strength, float damping, float restLength )
particles[i][j] = physics.makeParticle(0.2, j * gridStepX + (width / 4), i * gridStepY + 20, 0);
if (j > 0)
{
 springs[i][j] = physics.makeSpring(particles[i][j - 1], particles[i][j], 1.0, 0.5, sin(i)+30 );
}
   }
 }
 
 for (int j = 0; j < gridSize; j++)
 {
   for (int i = 1; i < gridSize; i++)
   {
 physics.makeSpring(particles[i - 1][j], particles[i][j], 1, 0.5, 20);
   }
 }
 for (int a = 0; a < gridSize; a++)
{
 float f = random(20);
 int b = int(f);
 particles[a][0].makeFixed();
 particles[0][a].makeFixed();
 particles[gridSize-1][a].makeFixed();
 particles[a][gridSize-1].makeFixed();
 //add switch loop to stop if value exceeds gridsize then try to use complex sequence to fix points
 particles[a][a].makeFixed();

}
//array of spring tension/compression store info for all springs and color_code
 //convert_type


//This is where I get the error!!!!!!!!!!





// end of the part I added that caused the error.

}

void draw()
{
 
 
 
 ////start of error part
 
   for (int y = 1; y < gridSize-1; y++)
 {
   for (int t = 1; t < gridSize-1; t++)
   {
int[] compressTest = new int[gridSize];
println("y="+y+" t="+t);
float stress = springs[y][t].restLength();  
int stressInt = int(stress);
println(stressInt);
compressTest[t] = stressInt;  
println("spring rest length is equal to " + compressTest[t]);
float compressTest2 = springs[y][t].currentLength();  
println("spring2 actual length is equal to " + compressTest2);
if ( stressInt < compressTest2 ){
   stroke(0, 255, 0);
 line(particles[y][t].position().x(),particles[y][t].position().y(), particles[y+1][t+1].position().x(),particles[y+1][t+1].position().y() );
 springs[y][t].turnOff();
}
if (compressTest2 < stressInt ){
 stroke(255, 0, 0);
 line(particles[y][t].position().x(),particles[y][t].position().y(), particles[y+1][t+1].position().x(),particles[y+1][t+1].position().y() );
 springs[y][t].turnOn();
}
   }
 }
 
 
 ///end of error part
 
 
 
 
 
 physics.advanceTime(0.1);
 
 if (mousePressed)
 {
   particles[0][gridSize - 1].moveTo(mouseX, mouseY, 0);
   particles[0][gridSize - 1].velocity().clear();
 }
 
 background(255);
 


}

void mouseReleased()
{
 particles[0][gridSize - 1].setVelocity( (mouseX - pmouseX), (mouseY - pmouseY), 0 );
}
Page Index Toggle Pages: 1