Skip to content

Commit

Permalink
Merge pull request #77 from abhikpal/master
Browse files Browse the repository at this point in the history
Chapter 4 Changed 'loc' to 'pos' (Example 8, flight404_particles_1_simple)
  • Loading branch information
shiffman committed Sep 19, 2016
2 parents b8e128d + 99335c0 commit 5482958
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 32 deletions.
5 changes: 2 additions & 3 deletions chp04_systems/NOC_4_08_ParticleSystemSmoke/Particle.pde
Expand Up @@ -14,7 +14,7 @@ class Particle {
float vx = randomGaussian()*0.3;
float vy = randomGaussian()*0.3 - 1.0;
vel = new PVector(vx,vy);
loc = l.get();
pos = l.get();
lifespan = 100.0;
img = img_;
}
Expand Down Expand Up @@ -57,5 +57,4 @@ class Particle {
return false;
}
}
}

}
5 changes: 2 additions & 3 deletions chp04_systems/NOC_4_08_ParticleSystemSmoke_b/Particle.pde
Expand Up @@ -17,7 +17,7 @@ class Particle {
float vx = (float) generator.nextGaussian()*0.3;
float vy = (float) generator.nextGaussian()*0.3 - 1.0;
vel = new PVector(vx,vy);
loc = l.get();
pos = l.get();
lifespan = 100.0;
img = img_;
}
Expand Down Expand Up @@ -60,5 +60,4 @@ class Particle {
return false;
}
}
}

}
5 changes: 2 additions & 3 deletions chp04_systems/flight404/flight404_particles_1_simple/NOC_gl.pde 100755 → 100644
Expand Up @@ -2,12 +2,11 @@
// Daniel Shiffman
// http://natureofcode.com

void renderImage(PImage img, Vec3D _loc, float _diam, color _col, float _alpha ) {
void renderImage(PImage img, Vec3D _pos, float _diam, color _col, float _alpha ) {
pushMatrix();
translate( _pos.x, _pos.y, _pos.z );
tint(red(_col), green(_col), blue(_col), _alpha);
imageMode(CENTER);
image(img,0,0,_diam,_diam);
popMatrix();
}

}
10 changes: 5 additions & 5 deletions chp04_systems/flight404/flight404_particles_1_simple/emitter.pde 100755 → 100644
Expand Up @@ -8,7 +8,7 @@ multiple emitters.
*/

class Emitter{
Vec3D loc;
Vec3D pos;
Vec3D vel;
Vec3D velToMouse;

Expand All @@ -17,7 +17,7 @@ class Emitter{
ArrayList particles;

Emitter( ){
loc = new Vec3D();
pos = new Vec3D();
vel = new Vec3D();
velToMouse = new Vec3D();

Expand Down Expand Up @@ -71,7 +71,7 @@ class Emitter{


void render(){
renderImage( emitterImg, loc, 150, myColor, 1.0 );
renderImage( emitterImg, pos, 150, myColor, 1.0 );
}

void iterateListRenderTrails(){
Expand All @@ -83,7 +83,7 @@ class Emitter{

void addParticles( int _amt ){
for( int i=0; i<_amt; i++ ){
particles.add( new Particle( loc, vel ) );
particles.add( new Particle( pos, vel ) );
}
}
}
}
35 changes: 17 additions & 18 deletions chp04_systems/flight404/flight404_particles_1_simple/particle.pde 100755 → 100644
Expand Up @@ -17,8 +17,8 @@ General Structure notes.

class Particle {
int len; // number of elements in position array
Vec3D[] loc; // array of position vectors
Vec3D startLoc; // just used to make sure every loc[] is initialized to the same position
Vec3D[] pos; // array of position vectors
Vec3D startpos; // just used to make sure every pos[] is initialized to the same position
Vec3D vel; // velocity vector
Vec3D perlin; // perlin noise vector
float radius; // particle's size
Expand All @@ -30,10 +30,10 @@ class Particle {
boolean ISBOUNCING; // if particle hits the floor...


Particle( Vec3D _loc, Vec3D _vel ) {
Particle( Vec3D _pos, Vec3D _vel ) {
radius = random( 10, 40 );
len = (int)( radius );
loc = new Vec3D[ len ];
pos = new Vec3D[ len ];

// This confusing-looking line does three things at once.
// First, you make a random vector.
Expand All @@ -45,10 +45,10 @@ class Particle {
// This is just a way to make sure all the particles made this frame
// don't all start on the exact same pixel. This staggering will be useful
// when we incorporate magnetic repulsion in a later tutorial.
startLoc = new Vec3D( _pos.add( new Vec3D().randomVector().scaleSelf( random( 5.0 ) ) ) );
startpos = new Vec3D( _pos.add( new Vec3D().randomVector().scaleSelf( random( 5.0 ) ) ) );

for( int i=0; i<len; i++ ) {
loc[i] = new Vec3D( startLoc );
pos[i] = new Vec3D( startpos );
}


Expand Down Expand Up @@ -87,8 +87,8 @@ class Particle {
}

void findPerlin() {
float xyRads = getRads( loc[0].x, loc[0].z, 10.0, 20.0 );
float yRads = getRads( loc[0].x, loc[0].y, 10.0, 20.0 );
float xyRads = getRads( pos[0].x, pos[0].z, 10.0, 20.0 );
float yRads = getRads( pos[0].x, pos[0].y, 10.0, 20.0 );
perlin.set( cos(xyRads), -sin(yRads), sin(xyRads) );
perlin.scaleSelf( .5 );
}
Expand All @@ -101,7 +101,7 @@ class Particle {
vel.addSelf( perlin );

if( ALLOWFLOOR ) {
if( loc[0].y + vel.y > floorLevel ) {
if( pos[0].y + vel.y > floorLevel ) {
ISBOUNCING = true;
}
else {
Expand All @@ -119,18 +119,18 @@ class Particle {
// Every frame, the current position will be passed on to
// the next element in the position array. Think 'cursor trail effect'.
for( int i=len-1; i>0; i-- ) {
loc[i].set( loc[i-1] );
pos[i].set( pos[i-1] );
}

// Set the initial position.
// loc[0] represents the current position of the particle.
loc[0].addSelf( vel );
// pos[0] represents the current position of the particle.
pos[0].addSelf( vel );
}

void render() {
// As the particle ages, it will gain blue but will lose red and green.
color c = color( agePer, agePer*.75, 1.0 - agePer );
renderImage(particleImg, loc[0], radius * agePer, c, 1.0 );
renderImage(particleImg, pos[0], radius * agePer, c, 1.0 );
}

void renderTrails() {
Expand All @@ -139,9 +139,9 @@ class Particle {
beginShape(QUAD_STRIP);
for ( int i=0; i<len - 1; i++ ) {
float per = 1.0 - (float)i/(float)(len-1);
xp = loc[i].x;
yp = loc[i].y;
zp = loc[i].z;
xp = pos[i].x;
yp = pos[i].y;
zp = pos[i].z;

if ( i < len - 2 ) {
// Okay, here is some vector craziness that I probably cant explain very well.
Expand All @@ -162,7 +162,7 @@ class Particle {
// this particular piece of source which has no camera object is I have replaced the eyeNormal
// (which would be the vector pointing from ribbon towards camera) with a generic Vec3D(0, 1, 0).
// Why? Well cause it works and thats enough for me. WHEE!
Vec3D perp0 = loc[i].sub( loc[i+1] );
Vec3D perp0 = pos[i].sub( pos[i+1] );
Vec3D perp1 = perp0.cross( new Vec3D( 0, 1, 0 ) ).normalize();
Vec3D perp2 = perp0.cross( perp1 ).normalize();
perp1 = perp0.cross( perp2 ).normalize();
Expand Down Expand Up @@ -205,4 +205,3 @@ class Particle {
}
}
}

0 comments on commit 5482958

Please sign in to comment.