Interesting effect on failed meta-balls project

Code
ArrayList<ball> balls = new ArrayList<ball>();
void setup() {
  size(600,600);
  for(int i = 0; i < 10; i++) {
    balls.add(new ball(random(width),random(height),random(10,15),cos(random(TWO_PI))*5, sin(random(TWO_PI))*5,((random(100)>50)? 1 :  1)));
  }
}
void draw() {
  loadPixels();
  for(int i = 0; i < width; i++) for(int j = 0; j < height; j++) {
    int pID = i+j*width;
    //int index = px + py * width;
    //  int sum = 0;
    //  for(int i = 0; i < bCount; i++) {
    //    float d = dist(px,py,x[i],y[i]);
    //    sum += 50 * r[i]/d;
    //  }
    //  pixels[index] = color(sum);
    int sum = 0;
    for(int k = 0; k < balls.size(); k++) {
      balls.get(k).update();
      float d = dist(i,j,balls.get(k).x,balls.get(k).y);
      sum += 50*balls.get(k).r/d*balls.get(k).m;
    }
    pixels[pID] = color(sum);
  }
  updatePixels();
}
class ball {
  float x, y, r, xs, ys, m;
  ball(float x_, float y_, float r_, float xs_, float ys_, float m_) {
    x = x_; y = y_; r = r_; xs = xs_; ys = ys_; m = m_;
  }
  void update() {
    x+=xs;
    y+=ys;
    if(y+r>height||y-r<0) ys*=-1;
    if(x+r>width||x-r<0) xs*=-1;
  }
}

It’s kinda like tv static, but it moves in an interesting pattern. Try it!

Edit: btw the issue with the program was that I was updating the movement of the balls while I calculated the pixel brightness.

1 Like

i hope one day i will fail my codes as you do…
thanks for sharing

1 Like

Great work and very nice