The turtle commands are found in the Prolog text "turtle.p". This Prolog text is loaded by the main HTML page. The turtle commands were written in Prolog itself. The turtle has a state represented as dynamic facts, consisting of the orientation and position of the turtle:
:- dynamic current_angle/1.
:- dynamic current_position/2.
The turtle commands are turn/1, move/1 and line/1. As a side effect they not only change the turtle state but they might also emit SVG commands. This is the case for the line/1 command which will draw a line on a SVG port:
line(D) :-
retract(current_position(X1, Y1)),
current_angle(A),
X2 is X1+D*cos(A),
Y2 is Y1+D*sin(A),
assertz(current_position(X2, Y2)),
line_svg(X1, Y1, X2, Y2).
We first planned to include some speed parameter when drawing the turtle. But the current version of Dogelog player yields automatically around 60 times per second which gives a kind of animation by itself, since this yielding is currently clamped at 4ms by the browser. In a future version of this tutorial example, we might do it differently.