Skip to content

Instantly share code, notes, and snippets.

@claytical
Created October 3, 2015 16:50
Show Gist options
  • Save claytical/1bde490f08b2aba5ec36 to your computer and use it in GitHub Desktop.
Save claytical/1bde490f08b2aba5ec36 to your computer and use it in GitHub Desktop.
Simple Object with Array Example
var Ball = function() {
this.x = mouseX;
this.y = mouseY;
this.diameter = 10;
}
var balls = [];
function setup() {
createCanvas(windowWidth, windowHeight);
}
function draw() {
background(0);
for (var i = 0; i < balls.length; i++) {
ellipse(balls[i].x, balls[i].y, balls[i].diameter, balls[i].diameter);
}
}
function mousePressed() {
balls.push( new Ball() );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment