Skip to content

Instantly share code, notes, and snippets.

@villares
Last active February 23, 2017 17:38
Show Gist options
  • Save villares/7fc6b17aeb34f360e752984c8b8ceaa9 to your computer and use it in GitHub Desktop.
Save villares/7fc6b17aeb34f360e752984c8b8ceaa9 to your computer and use it in GitHub Desktop.
var lista_de_bolas = []; // variável global para guardar bolas
function setup() {
createCanvas(800,600);
}
function draw() {
background(0)
for (var i = 0; i < lista_de_bolas.length; i++) { // itera pela lista de bolas
lista_de_bolas[i].desenha();
lista_de_bolas[i].move();
}
}
function mousePressed(){
var nova_bola = new Bola(mouseX, mouseY); // instancia uma nova bola
lista_de_bolas.push(nova_bola); // acrescenta a nova bola na lista
}
// 'Classe' Bola
function Bola(x_,y_){
this.x = x_;
this.y = y_;
this.tamanho = random(10,40);
this.cor = color(random(255),random(255),random(255));
this.vel_x = random(-2,2)
this.vel_y = random(-2,2);
this.desenha = function(){
fill(this.cor)
ellipse(this.x, this.y, this.tamanho,this.tamanho)
}
this.move = function(){
this.x = this.x + this.vel_x
this.y = this.y + this.vel_y
// this.vel_y = this.vel_y + 0.02; // gravidade
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment