Skip to content

Instantly share code, notes, and snippets.

@zamfi
Forked from cantor10000/circles-arrays.js
Created February 14, 2018 19:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zamfi/6d0cf997c2585c6639e4517941af90a7 to your computer and use it in GitHub Desktop.
Save zamfi/6d0cf997c2585c6639e4517941af90a7 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