Log in to post a comment.

// You can find the Turtle API reference here: https://turtletoy.net/syntax
Canvas.setpenopacity(1);

// Global code will be evaluated once.
const turtle = new Turtle();
turtle.penup();
// turtle.goto(-50,-20);
turtle.goto(0,50);
turtle.pendown();

var stringx = recurse("F", 0)

function recurse(str,stack){
    let newstr = "";
    let  i = 0
    while(i < str.length){
        if(str[i] == 'F'){
            newstr += "F+H";
        }else if(str[i] == 'H'){
            newstr += "F-H";
        } else {
            newstr += str[i];
        }
        i++;
    }
    if(stack<14){
        console.log(i)
        str = recurse(newstr, stack+1)
    }
    return str;
}

// The walk function will be called until it returns false.
function walk(i) {
    // turtle.forward(100);
    // turtle.right(144);
    // return i < 4;
    
    length = 1;
    // str = "F+H+F-H"
    //colorVar = 0.0;
    let str = stringx
    for(let i = 0; i < str.length; i++)
    {
        if(str[i] == 'F' || str[i] == 'H'){
            turtle.forward(length);
        } else if(str[i] == '+'){
            turtle.right(90);
        } else if(str[i] == '-'){
            turtle.left(90);
        } 
        // else if(str[i] == '['){
        //     turt.pushState();
        // } else if(str[i] == ']'){
        //     turt.popState();
        // }
        // if((float)i > (float)str.length() * colorVar ){
        //     turt.changeColor( (0.0 + colorVar), abs(0.5 - colorVar), (1.0 - colorVar));
        //     colorVar += 0.1;
        // }
    }
    return false
}