コード例 #1
0
    void wander() {
      float wanderR = 10.0f; // radius for our "wander circle"
      float wanderD = 20.0f; // distance for our "wander circle"
      wandertheta += random(-1, 1); // randomly changet wander theta

      // now we have to calculate the new location to steer towards on the wander circle
      Vector3D v = vel.copy();
      v.normalize(); // our heading
      float xoff =
          wanderD * v.x() + wanderR * cos(wandertheta); // x spot on circle based on heading
      float yoff =
          wanderD * v.y() + wanderR * sin(wandertheta); // y spot on circle based on heading
      Vector3D target = Vector3D.add(loc, new Vector3D(xoff, yoff)); // add the location
      acc.add(steer(target, false)); // steer towards it
    }
コード例 #2
0
 // function to display
 void render() {
   ellipseMode(CENTER);
   noStroke();
   fill(0, 100, 255, timer);
   ellipse(loc.x(), loc.y(), r, r);
 }