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

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();
  }

1 Like

How have you declared the global variable particles?
It’s important to define the datatype of the items a container stores (generics):

2 Likes

WOW, Thanks for your help! I realized what the problem was and I could fix the code error.
by the way, I’m a rookie just learning to program! :grinning: :grinning:

2 Likes