# Avoiding randomness in my sketch

**URL:** <https://discourse.processing.org/t/avoiding-randomness-in-my-sketch/14287>\
**Category:** Coding Questions\
**Created:** [September 29, 2019, 5:52pm UTC](https://discourse.processing.org/t/avoiding-randomness-in-my-sketch/14287 "2019-09-29T17:52:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![JoseBri93](https://avatars.discourse-cdn.com/v4/letter/j/a698b9/32.png) [@JoseBri93](https://discourse.processing.org/u/JoseBri93)\
**Post date:** [September 29, 2019, 5:52pm UTC](https://discourse.processing.org/t/avoiding-randomness-in-my-sketch/14287/1 "2019-09-29T17:52:02Z")

</div>

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!

```auto
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:

```auto
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;
  }
  }
}

```

---

<div class="post-metadata">

**Author:** ![jb4x](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jb4x/32/789_2.png) [@jb4x](https://discourse.processing.org/u/jb4x)\
**Post date:** [September 29, 2019, 7:31pm UTC](https://discourse.processing.org/t/avoiding-randomness-in-my-sketch/14287/2 "2019-09-29T19:31:31Z")

</div>

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](https://natureofcode.com/book/chapter-6-autonomous-agents/) 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.

---

<div class="post-metadata">

**Author:** ![Arjuna](https://avatars.discourse-cdn.com/v4/letter/a/da6949/32.png) [@Arjuna](https://discourse.processing.org/u/Arjuna)\
**Post date:** [September 29, 2019, 9:15pm UTC](https://discourse.processing.org/t/avoiding-randomness-in-my-sketch/14287/3 "2019-09-29T21:15:27Z")

</div>

**Noise** is what you are looking for!

Check it in 👉🏼 [the docs](https://processing.org/reference/noise_.html) 👈🏼.

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

Also, [this](https://necessarydisorder.wordpress.com/2017/11/15/drawing-from-noise-and-then-making-animated-loopy-gifs-from-there/) is a nice tutorial for more advanced uses of noise.

Have a good one!

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [October 3, 2019, 6:28am UTC](https://discourse.processing.org/t/avoiding-randomness-in-my-sketch/14287/4 "2019-10-03T06:28:50Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![JoseBri93](https://avatars.discourse-cdn.com/v4/letter/j/a698b9/32.png) [@JoseBri93](https://discourse.processing.org/u/JoseBri93)\
**Post date:** [October 7, 2019, 8:31pm UTC](https://discourse.processing.org/t/avoiding-randomness-in-my-sketch/14287/5 "2019-10-07T20:31:39Z")

</div>

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