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.
Page Index Toggle Pages: 1
traer.physics (Read 3150 times)
traer.physics
Jun 24th, 2007, 11:01pm
 
hello,

i want to make a particle rain fall down from above the
screen and replenishes a blob made with the blobdetection from v3ga. ths should consits out of rect() (pixel). so that a few particle fall down and
rotate. it would be nice if somebody could send me a hint or maybe a bit code to get the rain flow.

thanks henning
Re: traer.physics
Reply #1 - Jun 24th, 2007, 11:18pm
 
a simple test for rain could be to randomly place particles across your viewport (width) and apply gravity to it..
if also could take wind into account so the particles gain some kind of angle. is that what u want?
i did not get the idea of the blob thing.. dont know that
Re: traer.physics
Reply #2 - Jun 24th, 2007, 11:38pm
 
the idea with the blobdetection is to fill the edge vertex. make a grid to create a pixel silhouette on a screen. so the pixel fall down and bulid up the silhouett. when you move pixel fall down but new will come. like the sandman from spiderman.
Re: traer.physics
Reply #3 - Jun 25th, 2007, 1:17pm
 
how i manage the rotation of the particle?

import traer.physics.*;

Particle b;
ParticleSystem physics;

void setup()
{
 size( 400, 650 );
 frameRate( 24 );
 smooth();
 rectMode( CENTER );
 noStroke();
 noCursor();
 
 physics = new ParticleSystem( 0.5, 0.1 );
 b = physics.makeParticle( 0.4, 100, 0, 0 );
 b.makeFree();
}

void draw()
{
 handleBoundaryCollisions( b );
 physics.tick();

 background( 255 );
 
 fill( 0 );
 rect( b.position().x(), b.position().y(), 20, 20 );
}

// really basic collision strategy:
// sides of the window are walls
// if it hits a wall pull it outside the wall and flip the direction of the velocity
// the collisions aren't perfect so we take them down a notch too
void handleBoundaryCollisions( Particle p )
{
 if ( p.position().x() < 0 || p.position().x() > width )
   p.setVelocity( -0.9*p.velocity().x(), p.velocity().y(), 0 );
 if ( p.position().y() < 0 || p.position().y() > height )
   p.setVelocity( p.velocity().x(), -0.9*p.velocity().y(), 0 );
 p.moveTo( constrain( p.position().x(), 0, width ), constrain( p.position().y(), 0, height ), 0 );
}
Re: traer.physics
Reply #4 - Jun 25th, 2007, 5:18pm
 
try sumtin like

for every particle
{
 pushMatrix();
 rotate( ... )
 popMatrix();
}

to get a realistic effect u will have to play a bit with it..
Re: traer.physics
Reply #5 - Jun 27th, 2007, 4:54pm
 
got it!

another question:
can i get the attraction status from a particle?

Particle temp;
boolean status;
status = temp.isOn(); // ?

becaus the funktion boolean boolean isOn() ist just for Attraction objects?!?!
Re: traer.physics
Reply #6 - Jun 27th, 2007, 6:12pm
 
i havent played with traer physics but i think the isOn method is just to enable or disable an attraction force field..
im not sure what you are trying to do, can u tell us what exactly you're trying to achieve, there might be some "hack" or sumtin.. =)
Re: traer.physics
Reply #7 - Jun 27th, 2007, 7:05pm
 
i splited the resolution 640*480 in a raster of 160 * 120 "pixel" with a size of 4*4 normal pixel. i've made an 2D array[][] to store boolan. now theire are pixel shapes to store into this array like a rect of 4*4 pixel (in the transformed resolution). when the pixel rain falls down the pixel should fill this shape. so i made an array for the rain filled with particles and an array for static particle to which the rain particle get attracted. now i want to loop through the rain particle to get the status if it already gets attracted or not.

this is what i've done till now:

import traer.physics.*;

Particle b, c;
ParticleSystem rain,statics;

boolean raster[][];

int numPixels_w;
int numPixels_h;
int blockSize = 4;

void setup()
{
 size( 640, 480 );
 frameRate( 24 );
 numPixels_w = width / blockSize;
 numPixels_h = height / blockSize;
 raster = new boolean[numPixels_w+1][numPixels_h+1];
 smooth();
 rectMode( CENTER );
 noStroke();
 noCursor();
 
 rain = new ParticleSystem( 0.5, 0.1 );
 statics = new ParticleSystem( 0, 0.1 );
 
 createStatics();
 createRain();
}

float i = random(PI*2); // random rotation (value between 0 - PI*2)

void draw()
{
 background( 255 );
 rain.tick();

 fill( 0 );
 
 checkStatics();
 drawStatics();
 checkRain();
 drawRain();

 i+=random(0.1,0.2);
}

void createRain(){
 for(int i = 0; i<100; i++){
   Particle temp = rain.makeParticle( random(0.2, 1), random(width), random(-1000), 0 );
 }
}

void drawRain(){
 for(int z = 0; z < rain.numberOfParticles(); z++){
   Particle temp = rain.getParticle( z );
   pushMatrix();
   translate(temp.position().x(), temp.position().y());
   rotate(i);
   rect( 0, 0, 4, 4 );
   popMatrix();
 }
}

void checkRain(){
 for(int z = 0; z < rain.numberOfParticles(); z++){
   Particle temp = rain.getParticle( z );
   if(temp.position().y() > (height + 4)){
     temp.moveTo( random(width), random(-1000), 0 );
   }
 }
}

void createStatics(){
 for(int i = 0; i<100; i++){
   Particle temp = statics.makeParticle();
 }
}

void drawStatics(){
 for(int z = 0; z < statics.numberOfParticles(); z++){
   Particle temp = statics.getParticle( z );
   pushMatrix();
   translate(temp.position().x(), temp.position().y());
   rect( 0, 0, 8, 8 );
   popMatrix();
 }
}

void checkStatics(){
 int z = 0;
 for(int j = 0; j < numPixels_h; j++){
   for(int i = 0; i < numPixels_w; i++){
     if(raster[i][j] == true){
       // Position des statics Particle -> temp
       float pos_s_x = i * blockSize; // x
       float pos_s_y = j * blockSize; // y
       Particle temp = statics.getParticle( z );
       temp.moveTo( pos_s_x, pos_s_y, 0 );
       for(int t = 0; t < rain.numberOfParticles(); t++){
         Particle r_temp = rain.getParticle( t );
         // Position des rain Particle -> r_temp
         float pos_r_x = r_temp.position().x(); // x
         float pos_r_y = r_temp.position().y(); // y
         float d = dist(pos_s_x, pos_s_y, pos_r_x, pos_r_y);
         if( d < 10 ){
           rain.makeAttraction( temp, r_temp , 100, 25 );
           break;
         }
       }
       z++;
     }
   }
 }
}

void clearRaster(){
 for(int j = 0; j<numPixels_h; j++){
   for(int i = 0; i<numPixels_w; i++){
     raster[i][j] = false;
   }
 }
}

void keyPressed() {
 if (keyCode == UP) {
   raster[75][60] = true;
   raster[76][60] = true;
   raster[77][60] = true;
   raster[78][60] = true;
   raster[79][60] = true;
   raster[80][60] = true;
   raster[81][60] = true;
   raster[82][60] = true;
   raster[83][60] = true;
   raster[84][60] = true;
   raster[85][60] = true;
 }
 if (keyCode == DOWN) {
   clearRaster();
 }
}
Re: traer.physics
Reply #8 - Jun 29th, 2007, 10:52am
 
if i understand correctly, you are trying to paint a certain region of the screen when a particle in within bounds..

you will have to test "collision" for each section for each particle..

like:


for every particle
 get particle position

 for every screen section
 is particle within block? which block?
   if this is true, paint that block
Page Index Toggle Pages: 1