Example Uses

As an example, we were drawing the Sierpinski triangle. The fractal can be drawn with a cer-tain depth L. For depth L=0 only an equilateral triangle is drawn with length D. This can be done with Prolog by means of the turtle commands. The Prolog code is seen here:

sierpinski(D, 0) :- !, line(D), turn(-pi*2/3), line(D),
turn(-pi*2/3), line(D), turn(pi*4/3).

For depth L>0 the routine sierpinski/2 will call itself 3 times. It will first call for the left bottom, then for the right bottom and finally for the middle top. Between these invocations we move the turtle without drawing:

sierpinski(D, L) :- D1 is D/2, L1 is L-1,
sierpinski(D1, L1), move(D1), sierpinski(D1, L1),
turn(-pi*2/3), move(D1), turn(pi*2/3), sierpinski(D1, L1),
turn(pi*2/3), move(D1), turn(-pi*2/3).

Since the Dogelog player is automatically yielding, we get a little animation. In a future version we might even add some more animation, like a little turtle, but here the animation is only the result of successively adding line segments. Here is an example end-result:


Picture 5: Turtle Graphics with Sierpinski L=7

Kommentare