-
-
Save zamfi/6d0cf997c2585c6639e4517941af90a7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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