# Interesting effect on failed meta-balls project

**URL:** <https://discourse.processing.org/t/interesting-effect-on-failed-meta-balls-project/31244>\
**Category:** Gallery\
**Created:** [July 14, 2021, 8:13am UTC](https://discourse.processing.org/t/interesting-effect-on-failed-meta-balls-project/31244 "2021-07-14T08:13:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![CodeMasterX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/codemasterx/32/2942_2.png) [@CodeMasterX](https://discourse.processing.org/u/CodeMasterX)\
**Post date:** [July 14, 2021, 8:13am UTC](https://discourse.processing.org/t/interesting-effect-on-failed-meta-balls-project/31244/1 "2021-07-14T08:13:41Z")

</div>

![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/c/c98dd35931aaa8f37da8211f113c5244e9c025a1.jpeg)

> **Code**
>
> ```auto
> 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.

---

<div class="post-metadata">

**Author:** ![th75](https://avatars.discourse-cdn.com/v4/letter/t/ebca7d/32.png) [@th75](https://discourse.processing.org/u/th75)\
**Post date:** [July 16, 2021, 12:20am UTC](https://discourse.processing.org/t/interesting-effect-on-failed-meta-balls-project/31244/2 "2021-07-16T00:20:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [July 19, 2021, 9:28pm UTC](https://discourse.processing.org/t/interesting-effect-on-failed-meta-balls-project/31244/3 "2021-07-19T21:28:39Z")

</div>

Great work and very nice
