Skip to content

Instantly share code, notes, and snippets.

@cantor10000
Last active February 14, 2018 19:14
Show Gist options
  • Save cantor10000/06db1ccd1bfb82fa1118952785b3b56a to your computer and use it in GitHub Desktop.
Save cantor10000/06db1ccd1bfb82fa1118952785b3b56a to your computer and use it in GitHub Desktop.
var x = [];
var y = [];
var xSpeed = [];
var ySpeed = [];
var colors = [];
function setup() {
createCanvas(400, 400);
for (var index = 0; index < 100; index = index + 1) {
x[index] = width / 2;
y[index] = height / 2;
xSpeed[index] = random(-5, 5);
ySpeed[index] = random(-5, 5);
colors[index] = color(random(255), random(255), random(255))
}
}
function draw() {
background(0);
noStroke();
for (var index = 0; index < 100; index = index + 1) {
fill(colors[index]);
ellipse(x[index], y[index], 10);
x[index] = x[index] + xSpeed[index];
y[index] = y[index] + ySpeed[index];
if (x[index] > width - 5) {
xSpeed[index] = -xSpeed[index];
}
if (y[index] > height - 5) {
ySpeed[index] = -ySpeed[index];
}
if (x[index] < 5) {
xSpeed[index] = -xSpeed[index];
}
if (y[index] < 5) {
ySpeed[index] = -ySpeed[index];
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment