Skip to content

Instantly share code, notes, and snippets.

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