Random Distribution
The most obvious application of the for-loop in Processing is the distribution of elements. There are several possibilities here. The simplest of them is random distribution.
Processing
void setup() {
size(900, 900);
}
void draw() {
background(0);
for (int i = 0; i < 10; i++) {
ellipse(random(width), random(height), 50, 50);
}
}
P5.js
function setup() {
createCanvas(500, 500);
}
function draw() {
background(0);
for (let i = 0; i < 10; i++) {
ellipse(random(width), random(height), 50, 50);
}
}
Related Links
Published by Tim on Wednesday December 30, 2020