xxxxxxxxxx
45
let WIDE = 800;
let HIGH = 500;
let n = 4; // number of used reference points
let PGRID, CLOUDS, DISTA, ALPHA;
let i, x, y;
function setup() {
createCanvas(WIDE, HIGH);
// Create some reference Points
PGRID = new Array(2, n);
PGRID[0] = new Array(2);
PGRID[1] = new Array(n);
for (i = 0; i < 10; i++){
PGRID[0][i] = floor(random(50,WIDE-50));
PGRID[1][i] = floor(random(50,HIGH-50));
}
// Fill the Sky (CLOUDS) with R/G value dependent on n reference Points
CLOUDS = new Array(WIDE / 5, HIGH / 5);
for (x = 0; x < WIDE / 5; x++) {
CLOUDS[x] = new Array(WIDE / 5);
for (y = 0; y < HIGH / 5; y++) {
DISTA = 0;
for (i = 0; i < n; i++) {
DISTA = DISTA + dist(x*5,y*5,PGRID[0][i],PGRID[1][i]);
ALPHA = map(DISTA/i - 100,0,800,255,0);
CLOUDS[x][y] = ALPHA;
}
}
}
}
// Draw the Sky with Clouds (CLOUDS)
function draw() {
background(150,200,250); noStroke();
for (x = 0; x < WIDE / 5; x++) {
for (y = 0; y < HIGH / 5; y++) {
fill(CLOUDS[x][y], CLOUDS[x][y], CLOUDS[x][y], CLOUDS[x][y]);
square(x * 5, y * 5, 5);
}
}
noLoop;
}