xxxxxxxxxx
43
function randomInteger (min, max) {
return Math.floor(min + ((max-min) * Math.random()))
}
function pick (inputArray) {
return inputArray[randomInteger(0,inputArray.length)]
}
function buildArray (n, fillFunction) {
let outputArray = [];
for (let i = 0; i < n; i++) {
outputArray.push(fillFunction(i))
}
return outputArray
}
function setup() {
createCanvas(1000, 1000);
noLoop();
}
let someRandomScaleFactors = buildArray(500,i => 0.7 + (0.2 * Math.random()))
function simpleShape (moveX, moveY, scaleFactor) {
beginShape();
vertex(moveX, moveY);
vertex(scaleFactor * (moveX + 250), scaleFactor * (moveY+50));
vertex(scaleFactor * (moveX + 150), scaleFactor * (moveY + 450));
vertex(scaleFactor * (moveX + 50), scaleFactor * (moveY + 250));
endShape(CLOSE); // draws the lines for all sides because of CLOSE
}
function draw() {
background(220);
for (let i = 0; i < someRandomScaleFactors.length; i++){
fill(100 * Math.random(),200 + (50 * Math.random()),50 * Math.random());
simpleShape (100 + (20*(i%32)),
100 + (20 * (Math.floor(i/10))),
someRandomScaleFactors[i])
}
}