HAG
YaBB Newbies
Offline
Posts: 8
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(); } }