Random Distribution • tim rodenbröker creative coding

Random Distribution

Courses / Mastering the For-Loop / 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

Last modified on January 18th, 2023 at 12:40

  1. Anatomy of the For-Loop
  2. Random Distribution
  3. Linear Distribution
  4. Circular Distribution
  5. Circular Distribution (Examples)
  6. Two-dimensional distribution
  7. Two-dimensional distribution (Examples)
  8. Truchet Patterns
  9. Centering a Grid System
  10. Wrapping Up