void randomWalk(Mimo m) { Simulation1.app.noiseSeed(Simulation1.app.millis()); float speed = Simulation1.app.noise(Simulation1.app.frameCount * 0.1f) * maxSpeed; if (Simulation1.app.random(1) < 0.99) { return; } float a = PApplet.map( Simulation1.app.random(1), 0, 1, directionChangeRange.x, directionChangeRange.y); m.vel = new PVector(PApplet.cos(a), PApplet.sin(a)); m.vel.mult(speed); }
private void update(Mimo m) { if (m.ancestor && (m.pos.x <= 0 || m.pos.x >= Simulation1.screenWidth || m.pos.y <= 0 || m.pos.y >= Simulation1.screenHeight)) { // orient the ancestor towards the center float a = PApplet.atan2( Simulation1.screenHeight / 2 - m.pos.y, Simulation1.screenWidth / 2 - m.pos.x); m.vel = new PVector(PApplet.cos(a), PApplet.sin(a)); float speed = Simulation1.app.noise(Simulation1.app.frameCount * 0.1f) * maxSpeed; m.vel.mult(speed); } else { randomWalk(m); } m.pos.add(m.vel); }