//defining the particle class Part { //defines variables public float xo, yo, x, y; float r, rn, angn, angdelt, rot; float dxt, dyt, dx, dy; int spnum; boolean scattered = false; int id=0; int appear = 0; //for color float scRed = 0; float scGreen = 0; float scBlue = 255; float scAlpha = 0; public boolean alive; //to increase the radius of the swirl later on - heat behaviour float bigger = 10; //the higher the value of 'a' the further the particles scatter - collision with monster //0 for gentle movement - 1.1 for big expansion!!! float a = 0; //properties of each particle - takes 2 parameters x & y Part(float x, float y, boolean b) { alive = b; //is the particle alive this.x = (int)(x); this.y = (int)(y); //where on the screen this.xo = (int)(x); this.yo = (int)(y); this.angn = 0; this.rn = 0; this.dxt = 0; this.dyt = 0; this.dx = 0.0001; this.dy = 0.0001; this.angdelt = 0; this.rot = 0; } //start of particle methods /********************************************************************************/ //method to update the position & movement of a paticle public void update(float mlocxnew, float mlocynew, float mlocx, float mlocy) { float infOnPar = ((sqrt(pow((x - mlocxnew), 2) + pow((y - mlocynew),2)) +5)); // set up the linear displacement dx = ((msens*mxvel/infOnPar)+dx *a); dy = ((msens*myvel/infOnPar)+dy *a); // rotational influence calc if the coordinates // are moving to the left if (mlocy < y) rot = ((sens/infOnPar)*mvel); if (mlocy > y) rot = ((-sens/infOnPar)*mvel); // if the coordinates are moving to the right if (mlocxnew > mlocx) rot *= -1; // left nor right if(mlocxnew == mlocx) rot = .5; // calculate new angular velocity angdelt += rot; // set the new angle angn += angdelt; // calculate the radius of the swirl - bigger angle = further spread = heat behaviour rn = angdelt * bigger; // work out the radius from the rate of rotation if (abs(rn) < 1){ angn = 0; angdelt = 0; } // Decay the rate of rotation due to friction 'a' angdelt = angdelt * a; // Add displacement influence dxt += dx; dyt += dy; // calculate new x,y position of (each individual) particle y = (int)((cos(angn) * rn) + yo + dyt * a); x = (int)((sin(angn) * rn) + xo + dxt * a); }//end of update method /********************************************************************************/ //function to define the size, color & type of particles & draw on screen public void render() { if(appear <320){ stroke(0, scAlpha); fill(0, scAlpha); // ellipse(x,y,8,8); noStroke(); fill(scRed, scGreen, scBlue, scAlpha); ellipse(x,y,4,4); appear++; scAlpha +=2; } else if (appear == 320){ scAlpha = 255; stroke(0, scAlpha); fill(0, scAlpha); // ellipse(x,y,8,8); noStroke(); fill(scRed, scGreen, scBlue, scAlpha); ellipse(x,y,4,4); } } /********************************************************************************/ //everything here happens immediately - in order to delay the return to normal place in MAIN draw method! public void normalize(){ //restore colour normalColor(); //restore after heat if(bigger>10) { bigger-=3; } //restore after voltage if (mxvel >5 ) {mxvel -=0.1;} if (mxvel <5 ) {mxvel +=0.1;} if (myvel >10) {myvel-=0.1; } if (myvel <10) {myvel+=0.1; } if (mvel >124) {mvel-=0.1;} if (mvel <124) {mvel+=0.1; } }// end normalize /********************************************************************************/ //function for when hot sensor is triggered - key presss h at present public void scatter_hot() { //make the swirl bigger as the scatter brain gets hotter if(bigger<200) { bigger+=2; } } //end scatter_hot /********************************************************************************/ //function for when cold sensor is triggered - key presss c at present public void scatter_cold(){ if(this.xo > mySBX){ this.xo --; } if(this.xo < mySBX){ this.xo ++; } if(this.yo > mySBY){ this.yo --; } if(this.yo < mySBY){ this.yo ++; } if(this.yo == mySBY && this.xo == mySBX) { this.alive = false; } } //end scatter_cold /********************************************************************************/ //function for when disturb sensor is triggered - key presss v at present public void scatter_disturb(){ mxvel =800; myvel = 800; mvel = sqrt(pow(mxvel,2) + pow(myvel,2)); } //end scatter_disturb ///////////////ALL THESE COLOURS NEED TO BE CODED PROPERLY!!!!!!!////////////////// /********************************************************************************/ public void hotColor(){ if(scRed<252) scRed +=4; if(scRed>252) scRed -=4; if(scGreen>143) scGreen-=4; if(scGreen<143) scGreen+=4; if(scBlue>8) scBlue-=4; if(scBlue<8) scBlue+=4; } /********************************************************************************/ public void coldColor(){ if(scRed<101) scRed +=4; if(scRed>101) scRed -=4; if(scGreen>231) scGreen-=4; if(scGreen<231) scGreen+=4; if(scBlue>254) scBlue-=4; if(scBlue<254) scBlue+=4; } /********************************************************************************/ public void disturbColor(){ if(scRed<255) scRed +=10; if(scRed>255) scRed -=10; if(scGreen>255) scGreen-=10; if(scGreen<255) scGreen+=10; if(scBlue>0) scBlue-=10; if(scBlue<0) scBlue+=10; } /********************************************************************************/ public void normalColor(){ if(scRed<214) scRed +=4; if(scRed>214) scRed -=4; if(scGreen>200) scGreen-=4; if(scGreen<200) scGreen+=4; if(scBlue>200) scBlue-=4; if(scBlue<200) scBlue+=4; } /********************************************************************************/ public void killColor(){ scRed = 255; scGreen = 0; scBlue = 0; } /********************************************************************************/ //end of Particle class }