SketchBook

Well-being①

var cellX;
var cellY;
var time;
var colors = [];

function setup() {
createCanvas(windowWidth,
windowHeight);
background(255, 255, 255);
noStroke();


colors.push(color(120, 215, 240));
colors.push(color(200, 220, 235));
colors.push(color(245, 230, 235));
colors.push(color(250, 210, 210));
colors.push(color(255, 175, 120));
colors.push(color(255, 130, 90));

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(238, 238, 238, 100);
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]);
}

}

colors.push(color(255,0,0));
colors.push(color(255,127,80));
colors.push(color(255,165,0));
colors.push(color(240,230,140));
colors.push(color(255,255,0));

cellX = 50;
cellY = 50;

time = 0;


function draw() {
for (var y = 0; y < cellY; y = y + 1) {
for (var x = 0; x < cellX; x = x + 1) {
var val = noise(x / 100, y / 100, time);
var c = getColor(val);

var rectWidth = windowWidth / cellX;
var rectHeight = windowHeight / cellY;
var rectX = x * rectWidth;
var rectY = y * rectHeight;

fill(c);
rect(rectX, rectY, rectWidth, rectHeight);
}
}

time += 0.01;
}

function getColor(t) {
var p = t * (colors.length - 1);
var from = floor(p);
return lerpColor(colors[from], colors[from + 1], p - from);
}