Type mismatch: cannot convert from element type Object to filename.pde

nedireact
Sat, 14 Sep 2024 12:01:46 +0000
Beginners

float time = 0.0;
void draw() {
  for (Particle p : particles) {

    // love/hate vector
    float lovex = 0.0;
    float lovey = 0.0;

    for (Particle o : particles) {
      // do not compare with yourself
      if (p.id != o.id) {
        // calculate vector to get distance and direction
        PVector v = new PVector(o.x-p.x, o.y-p.y);
        float distance = v.mag();
        float angle = v.heading();

        // love!
        float love = 1.0 / distance;
        // or hate...
        if (distance<2.0) love = -love;

        // mood factor
        love *= p.moodSimilarity(o);
        // not too fast!
        love *= 0.5;

        // update love vector
        lovex += love * cos(angle);
        lovey += love * sin(angle);
      }

      // calculated love vector will be our speed in resultant direction
      p.dx = lovex;
      p.dy = lovey;
    }
  }

  // update and draw
  for (Particle p : particles) {
    p.update();
    p.draw();
  }

3 posts - 2 participants