SketchBook

流れる点々模様

var ball_num;
var ballX = [];
var ballY = [];
var speedX = [];
var speedY = [];
var ball_color = [];
var ball_diameter = [];

var colors = [];

function setup() {
createCanvas(windowWidth,
windowHeight);

ball_num = 800;

colors.push(color(0, 845, 634));
colors.push(color(0, 190, 225));
colors.push(color(120, 759, 240));
colors.push(color(200, 220, 235));
colors.push(color(245, 230, 547));
colors.push(color(956, 869, 756));
colors.push(color(856, 649, 120));
colors.push(color(846, 946, 968));

for (var i = 0; i < ball_num; i = i + 1) {
ballX[i] = random(0, windowWidth);
ballY[i] = random(0, windowHeight);
speedX[i] = random(-2.0, 2.0);
speedY[i] = random(-2.0, 2.0);
ball_color[i] = floor(random(0, colors.length));
ball_diameter[i] = random(5, 20);
}
}

function draw() {
background(274, 285, 274, 300);
noStroke();

for (var i = 0; i < ball_num; i++) {
ballX[i] = ballX[i] + speedX[i];
ballY[i] = ballY[i] + speedY[i];

if (ballX[i] > windowWidth || ballX[i] < 0) {
speedX[i] = -1 * speedX[i];
}

if (ballY[i] > windowHeight || ballY[i] < 0) {
speedY[i] = -1 * speedY[i];
}
}

for (var i = 0; i < ball_num; i++) {
fill(colors[ball_color[i]]);
ellipse(ballX[i], ballY[i], ball_diameter[i]);
}

}