Processing T-tree

T-systems, recursion, iterations.

by schrodingers

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/processing.js/1.4.15/processing.js"></script>
<canvas></canvas>

CSS

body {
    overflow: hidden;
    margin: 0;
    padding: 0;
}
</style> <script type="text/javascript"> window.addEventListener('load', function() {
    var scripts=document.body.getElementsByTagName('script');
    var canvases=document.body.getElementsByTagName('canvas');
    new Processing(canvases[0], scripts[0].text);
}
, false);
 // Here prevent javascript in body from throwing error </script> <style>

JavaScript

/* 
 title: p202 Recursion, iterations
 date: 2015-07-21
 */

int x = width / 2; // x center
int y = height / 2; // y bottom
int a = 55; // apex, topbar half-width
int lvl = 7; //lvl

void setup() {
    size(600, 400);
    smooth(8);
    //  noStroke();
    noLoop();
}
void draw() {
    // fill(0, 10);
    //  rect(0, 0, width, height);
    fill(255);
    translate(200, height);
    drawT(0, 0, 100, 7);
}

void drawT(int x, int y, int a, int lvl) {
    line(x, y, x, y - a);
    line(x - a, y - a, x + a, y - a);

    if (lvl > 0) {
        drawT(x - a, y - a, a / 2, lvl - 1);
        drawT(x + a, y - a, a / 2, lvl - 1);
    }

}