class Pellet { float x,y,z,vx,vy,vz,d; //------------------ Pellet(){ } //------------------ void cubeFormation(int side, float maxSpeed){ x = random(0,side)+width/2-side/2; y = random(0,side)+width/2-side/2; z = random(0,side)+width/2-side/2; vx = random(-maxSpeed,maxSpeed); vy = random(-maxSpeed,maxSpeed); vz = random(-maxSpeed,maxSpeed); } //------------------ void sphereFormation(int radius, float maxSpeed){ cubeFormation(2*radius, maxSpeed); if( dist(width/2,width/2,width/2,x,y,z) > radius ) cubeFormation(2*radius, maxSpeed); if( dist(width/2,width/2,width/2,x,y,z) > radius ) cubeFormation(2*radius, maxSpeed); if( dist(width/2,width/2,width/2,x,y,z) > radius ) cubeFormation(2*radius, maxSpeed); if( dist(width/2,width/2,width/2,x,y,z) > radius ) cubeFormation(radius, maxSpeed); } //------------------ void setFlightPath(float vx, float vy, float vz){ this.vx = vx; this.vy = vy; this.vz = vz; } //------------------ void update(){ x += vx; y += vy; z += vz; vx += gradX(x,y,z)*gravity; vy += gradY(x,y,z)*gravity; vz += gradZ(x,y,z)*gravity; d = mag(vx,vy,vz); vx = vx/d; vy = vy/d; vz = vz/d; screenImage[constrain((int)x,0,width-1)][constrain((int)y,0,width-1)] += opacity; } //------------------ void visualize(){ stroke( 128*noise(x,y,z),255,255,opacity); noFill(); ellipse(x,y,3,3); } //------------------ float gradX( float x, float y, float z){ return (noise(s*x+s,s*y,s*z) - noise(s*x-s,s*y,s*z)); } //------------------ float gradY( float x, float y, float z){ return (noise(s*x,s*y+s,s*z) - noise(s*x,s*y-s,s*z)); } //------------------ float gradZ( float x, float y, float z){ return (noise(s*x,s*y,s*z+s) - noise(s*x,s*y,s*z-s)); } } //---------------------------------------------