Avoiding randomness in my sketch

Hi!, i’m creating this sketch where bouncing balls go all over the display. It’s working fine however i want to know is there are other options to work instead of randomness to get diferrent organic ways for my objetcs to move, displace over the sketch.
PD: i check out for gaussian distribution in the moment to write this, still if you could give me tips i’d appreciate it. Good day!

Pelota[] pelotas = new Pelota[100];
import spout.*;

Spout spout;

void setup() {
  
  size(800,600, P2D);
  for (int i = 0; i < pelotas.length; i++) {
    pelotas[i] = new Pelota(random(150), random(100), random(255));
  }
  
  spout = new Spout(this);
  spout.createSender("Spout Processing");
}

void draw() {
  background(100);
  
  float d = map(mouseX, 0, width, 90, 0);  
  
  for (int i = (int(d)); i < pelotas.length; i++) {
  pelotas[i].display();
  pelotas[i].sinBorde();
  }
  
  spout.sendTexture();
}

My class is this:

class Pelota {
  PVector location;
  PVector velocity;
  
  float movX;
  float movY;
  
  float rojo;
  float verde;
  float azul;
  int size = 25;
  
  
  Pelota(float tempRed, float tempGreen, float tempBlue) {
    location = new PVector((random(width)), random(height)); 
   
    velocity = new PVector((random(-2, 2)), random(-2,2));
    rojo = tempRed;
    verde = tempGreen;
    azul = tempBlue;
  }
  
  void display() {
  
   
   fill(rojo, verde, azul);
   ellipse(location.x, location.y, size, size);
   location.add(velocity);
   
  }
  
  void sinBorde() {
   if((location.x > width) || (location.x < 0)) {
    velocity.x = velocity.x * -1;
  }
   if((location.y > height) || (location.y < 0)) {
    velocity.y = velocity.y * -1;
  }
  }
}
2 Likes

Hi,

One thing you might consider is to have, for each objects, a random target point that changes over the time (every 5 seconds for example).

Then you can code a steering behavior to move your object toward that target spot.

Since the target will randomly change over time, you should end up with a nice smooth random movement over the screen.

4 Likes

Noise is what you are looking for!

Check it in :point_right:t3: the docs :point_left:t3:.

It lets you do exactly that, have something that is not entirely random and feels organic.

Also, this is a nice tutorial for more advanced uses of noise.

Have a good one!

5 Likes

You can also distribute the initial ball positions and / or their angles geometrically, then set then in motion. This will create spirograph effects.

You can also change ball velocity based on position in the space – this will cause a cloud of random balls to pile up in slow zones and thin out in fast zones.

You can also begin with a long train of balls, all with the same angle / direction, and slowly shrink or grow the walls. This will cause dispersion, leading to spirograph effects.

1 Like

Thanks guys, appreciate it, i’ll try your tips and see what happens, Thanks a lot!