Objects staying together

Hey guys. So I created objects that move randomly around. I noticed that when they collide, they "become one" and move together on the same path. Any idea why this is happening? Or is it just coincidence?

//sketch.js
var count = 50;
var org = [];
function setup() {
    createCanvas(500,500);
    for(var i = 0; i < count; i++){
        org[i] = new Organism();
    }
}

function draw() {
    background(255);
    for(var i = 0; i < org.length; i++){
        org[i].move();
        org[i].display();
    }
}

function Organism(){
    this.size = random(15, 30);
    this.x = random(0, 500);
    this.y = random(0, 500);

    this.move = function(){
        this.x += (noise(this.x*0.034, this.y*0.034, frameCount*.021) - .5) * 15;
        this.y += (noise(frameCount*.021, this.x*0.034, this.y*0.034) - .5) * 15;
    };

    this.display = function(){
        ellipse(this.x, this.y, this.size, this.size);
    };
}

Answers

Sign In or Register to comment.