Turtle

2005 Klaus & Till Bovermann

A simple turtle implementation.

t = Turtle.new

(

t.init;

t.to(100@100);

t.turn(0.5pi);

t.penDown;

t.forward(100);

t.penUp;

t.turn(-0.5pi);

t.forward(100);

t.penDown;

t.forward(100);

)

w = SCWindow.new.front

(

w.drawHook = {

Pen.use {

t.stroke;

Color.red.set;

Pen.fillRect(Rect(100,100,4,4));

Color.green.set;

Pen.fillRect(Rect(0,0,4,4));

}

};

w.refresh;

)

f = {|turtle, length = 100, depth = 1|

if (depth <= 0, {

turtle.forward(length);

}, {

f.(turtle, length/3, depth-1);

// -60

turtle.turn(-pi*(1/3));

f.(turtle, length/3, depth-1);

// 120

turtle.turn(pi*(2/3));

f.(turtle, length/3, depth-1);

// -60

turtle.turn(-pi*(1/3));

f.(turtle, length/3, depth-1);

});

}

t = Turtle.new;

(

w = SCWindow.new.front;

w.drawHook = {

Pen.use {

Pen.rotate(0.2);

t.init;

t.to(100@100);

t.penDown;

f.(t, 200, 5);

t.turn(pi*(2/3));

f.(t, 200, 5);

t.turn(pi*(2/3));

f.(t, 200, 5);

t.stroke;

}

};

w.refresh;

)