Sierpinski Triangle

The Sierpinski triangle is a self-similar fractal.
Making principle is very simple, Just find the mid-point of two points of the triangle and find the mid point between the point and a random edge, and keep doing this.
More the iterations, more the detail.

Code

            
    elem=document.querySelector(".example-container");
    setCanvas(elem);
    
    x1=WIDTH/2;
    y1=HEIGHT/2-200;

    x2=WIDTH/2-sqrt(3)*100;
    y2=HEIGHT/2+100;

    x3=WIDTH/2+sqrt(3)*100;
    y3=HEIGHT/2+100;

    x=(x1+x2)/2;
    y=(y1+y2)/2;

    function draw() {

    //clearCanvas();
    new circle(x1,y1,2,'#fff',1,'#fff',0);
    new circle(x2,y2,2,'#fff',1,'#fff',0);
    new circle(x3,y3,2,'#fff',1,'#fff',0);

    decision=randomInt(1,4);
    console.log(decision);

    switch(decision){
        case(1):
        new circle((x+x1)/2,(y+y1)/2,2,'#fff',1,'#fff',0);
        x=(x+x1)/2;
        y=(y+y1)/2;
        break;
        case(2):
        new circle((x+x2)/2,(y+y2)/2,2,'#fff',1,'#fff',0);
        x=(x+x2)/2;
        y=(y+y2)/2;
        break;
        case(3):
        new circle((x+x3)/2,(y+y3)/2,2,'#fff',1,'#fff',0);
        x=(x+x3)/2;
        y=(y+y3)/2;
        break;   
    }

    requestAnimationFrame(draw);
    }

    draw();