curve

fun Turtle.curve(length: Double, curvature: (s: Double) -> Double)(source)

Moves the turtle length forward while it turns as sharply as curvature prescribes: curvature(s) is the turning rate, in radians per unit of length, after a distance s from 0 to length. Positive curvature turns the same way as a positive Turtle.rotate. Where the pen is down the path is drawn; afterwards the turtle faces the way the path ends.

The heading is the integral of the curvature and the position the integral of the heading, a curvature turtle as in Abelson and diSessa, "Turtle Geometry" (1981). Both are integrated with the classical Runge-Kutta method in steps that turn by at most 0.002 radians, and the path is drawn as cubic Béziers that turn by at most π/16 each, with their end points and end directions on the integrated path and handles of the length that is exact for a circular arc of the same turn.