Skip to content

Instantly share code, notes, and snippets.

@martijnkunstman
Created March 20, 2021 23:12
Show Gist options
  • Select an option

  • Save martijnkunstman/db9cd5eb4e9397d11fdfb8ba283efe6f to your computer and use it in GitHub Desktop.

Select an option

Save martijnkunstman/db9cd5eb4e9397d11fdfb8ba283efe6f to your computer and use it in GitHub Desktop.

Revisions

  1. martijnkunstman created this gist Mar 20, 2021.
    36 changes: 36 additions & 0 deletions script.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    let width = 700;
    let height = 700;

    let points = [
    { x: width / 2, y: 0 },
    { x: 0, y: height },
    { x: width, y: height }
    ];

    let pointNow = { x: width / 2, y: height / 2 };

    /*
    let points = [
    { x: 0, y: 0 },
    { x: width, y: 0 },
    { x: 0, y: height },
    { x: width, y: height },
    {x: width/2, y:height/2}
    ];
    */

    function setup() {
    createCanvas(width, height);
    stroke('rgba(0,0,0,0.25)');
    }

    function draw() {
    for (let i = 0; i < 1000; i++) {
    let pointNext = points[Math.floor(Math.random() * points.length)];
    pointNow = {
    x: (pointNext.x + pointNow.x) / 2,
    y: (pointNext.y + pointNow.y) / 2
    };
    point(pointNow.x, pointNow.y);
    }
    }
    1 change: 1 addition & 0 deletions scripts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.3.0/p5.min.js"></script>
    7 changes: 7 additions & 0 deletions sierpinski-triangle-chaos-game.markdown
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    Sierpiński triangle - Chaos game
    --------------------------------


    A [Pen](https://codepen.io/martijnkunstman/pen/yLVmPeg) by [Martijn Kunstman](https://codepen.io/martijnkunstman) on [CodePen](https://codepen.io).

    [License](https://codepen.io/martijnkunstman/pen/yLVmPeg/license).