class Thing { PVector loc; PVector vel; PVector acc; boolean walking; boolean slowing; boolean playing; float dur; float maxVel; int circle; float prob; //The Constructor (called when the object is first created) Thing(PVector a, PVector v, PVector l) { acc = a.get(); vel = v.get(); loc = l.get(); walking = false; slowing = false; playing = true; dur = random(200); maxVel = random(.05, .1); circle = 1; } //main function to operate object) void go() { render(); borders(); if(walking) {walk();} if(slowing) {slow();} if(playing) {play();} } //function to update location void walk() { vel.add(acc); loc.add(vel); if((abs(vel.x) >= maxVel) || (abs(vel.y) >= maxVel)){walking = false; slowing = true; playing = false;} } void slow(){ if (abs(vel.x) > 0.03){vel.x *= .97;loc.add(vel);} if (abs(vel.y) > 0.03){vel.y *= .97;loc.add(vel);} else {setXY(0.0f,0.0f);slowing = false; playing = true; walking = false;XYToCircle(loc.x, loc.y);} } void play(){ prob = random(10000); if(prob > 9995){newPlace();} } void setXY (float x, float y){ vel.x = x; vel.y = y; } void borders() { float disX = width/2 - loc.x; float disY = height/2 - loc.y; if(sqrt(sq(disX) + sq(disY)) > (width/2) ){ acc.x = -acc.x; acc.y = -acc.y; vel.x = -vel.x; vel.y = -vel.y; } } void newPlace(){ prob = random(2); //Most of the time, choose a random angle for your walk. if (prob < 1f){ acc.x= random (-.03,.03); acc.y= random (-.03,.03);} // Sometimes, choose to go towards the center. else if (prob >= 1f){ PVector diff = PVector.sub(celloThing.loc, loc); diff.normalize(); diff.mult(2.0); diff.x = acc.x; diff.y = acc.y; } maxVel = random(1, -1); walking = true; slowing = false; playing = false; dur = random(400); } //function to display void render() { rectMode(CENTER); noStroke(); fill(255, 181, 31, 160); ellipse(loc.x,loc.y,10,10); if (showVectors) { drawVector(vel,loc,10); } } int XYToCircle (float x, float y){ float disX; float disY; float rad; for(int iter = 8; iter > 0; iter--){ float distX = width/2 - loc.x; float distY = height/2 - loc.y; rad = (iter * width/7); if(sqrt(sq(distX) + sq(distY)) < rad/2 ){ circle = iter;} } return(circle); } }