Lynxer

Documentation

turtle

Classic turtle graphics: a pen that moves and turns, drawing as it goes.

Backend: pure — stdlib/turtle.lynx, a thin wrapper over the graphics module's turtle state machine (rust/graphics). The drawing goes through the ordinary shape ops, so it works with a window and on the headless rasterizer. Import: import("turtle") → global.turtle.*

State lives in graphics

Lynxer has no module-level mutable state, so a pure-Lynxer module cannot remember anything between calls. The turtle therefore lives in the graphics module as a handle; this module drives the implicit default turtle (handle 0), which graphics creates on first use. Programs that need several turtles use the graphics.turtle* ops with an explicit handle from graphics.turtleCreate(x, y, heading).

The heading is in degrees: 0 points east (+x) and increases clockwise, matching the screen's y-down coordinate system.

Functions

FunctionSignatureNotes
forward(float distance) -> intMove forward, drawing when the pen is down
back(float distance) -> intMove backward
turn / turnRight(float degrees) -> intTurn clockwise
turnLeft(float degrees) -> intTurn counter-clockwise
goto(float x, float y) -> intMove straight without turning
home() -> intReturn to the origin, facing east
penUp / penDown() -> intStop / resume drawing while moving
setColor(int r, int g, int b, int a = 255) -> intPen colour
setWidth(float width) -> intPen width in pixels
x / y() -> floatCurrent position
heading() -> floatCurrent heading in degrees
penIsDown() -> boolWhether the pen is down

Each op returns 0 on success (the movement ops) or the queried value; there is no failure sentinel because the default turtle always exists.

Example

global setup(){ import("turtle"); import("graphics"); }

global main(){
    global.graphics.init("turtle", 400, 400);
    global.graphics.clearBackground(255, 255, 255);

    global.turtle.setColor(0, 90, 200);
    global.turtle.setWidth(2.0);
    for (int i = 0; i < 4; i = i + 1){
        global.turtle.forward(120.0);
        global.turtle.turn(90.0);
    }

    println(global.turtle.x(), ",", global.turtle.y());
    println(global.turtle.heading());
}

See also