コード例 #1
0
  public void draw() {
    background(255);

    // Turn off highlighting for all obstalces
    for (int i = 0; i < obstacles.size(); i++) {
      Obstacle o = (Obstacle) obstacles.get(i);
      o.highlight(false);
    }

    // Act on all boids
    for (int i = 0; i < boids.size(); i++) {
      Boid b = (Boid) boids.get(i);
      b.avoid(obstacles);
      b.run();
    }

    // Display the obstacles
    for (int i = 0; i < obstacles.size(); i++) {
      Obstacle o = (Obstacle) obstacles.get(i);
      o.display();
    }

    // Instructions
    textFont(f);
    fill(0);
    text(
        "Hit space bar to toggle debugging lines.\nClick the mouse to generate a new boids.",
        10,
        height - 30);
  }
コード例 #2
0
  public void draw() {
    background(0);
    // Draw an ellipse at the mouse location
    int mx = mouseX;
    int my = mouseY;
    fill(100);
    noStroke();
    ellipse(mx, my, 30, 30);

    // call some behaviors on our agent
    // b.wander();
    // b.seek(new Vector3D(mx,my));
    b.arrive(new Vector3D(mx, my));
    b.run();
  }