Skip to content

Instantly share code, notes, and snippets.

@takawo
Last active May 24, 2022 11:10

Revisions

  1. takawo revised this gist May 24, 2022. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions recursiveRandomAndCircleStudy.js
    Original file line number Diff line number Diff line change
    @@ -7,13 +7,13 @@ function draw() {
    background((95 / 100) * 255);
    push();
    translate(width / 2, height / 2);
    let ratio = 0;
    let angle_num = 4;
    let ratio = 0.01;
    let angle_num = 10;
    for (let i = 0; i < 10000; i++) {
    let bool = random() > 0.5;
    let angle =
    (int(random(angle_num)) * 360) / angle_num +
    ((recursiveRandom(angle_num, bool) - 0.5) * 360) / angle_num / 2;
    ((recursiveRandom(3, bool) - 0.5) * 360) / angle_num / 2;
    let n = recursiveRandom(random(0, 5), bool);
    let r = 200 * n;
    let x = cos(angle) * r * (bool ? 1 - ratio : 1 + ratio);
    @@ -32,4 +32,4 @@ function recursiveRandom(count, bool = true) {
    count--;
    }
    return bool ? 1 - n : 1 + n;
    }
    }
  2. takawo created this gist May 24, 2022.
    35 changes: 35 additions & 0 deletions recursiveRandomAndCircleStudy.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    function setup() {
    createCanvas(800, 800);
    angleMode(DEGREES);
    }

    function draw() {
    background((95 / 100) * 255);
    push();
    translate(width / 2, height / 2);
    let ratio = 0;
    let angle_num = 4;
    for (let i = 0; i < 10000; i++) {
    let bool = random() > 0.5;
    let angle =
    (int(random(angle_num)) * 360) / angle_num +
    ((recursiveRandom(angle_num, bool) - 0.5) * 360) / angle_num / 2;
    let n = recursiveRandom(random(0, 5), bool);
    let r = 200 * n;
    let x = cos(angle) * r * (bool ? 1 - ratio : 1 + ratio);
    let y = sin(angle) * r * (bool ? 1 - ratio : 1 + ratio);
    strokeWeight(2 - abs(n - 1) * 2);
    point(x, y);
    }
    pop();
    noLoop();
    }

    function recursiveRandom(count, bool = true) {
    let n = 1;
    while (count > 0) {
    n *= random();
    count--;
    }
    return bool ? 1 - n : 1 + n;
    }