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