package lilis

  1. Overview
  2. Docs

Graphical primitives for drawing L-systems.

We use a logo-like system to draw a L-system : a turtle is following the order in the Lstream.

type pos = {
  1. mutable x : float;
  2. mutable y : float;
  3. mutable d : float;
}
type color = {
  1. r : float;
  2. g : float;
  3. b : float;
  4. a : float;
}
type orders =
  1. | Forward
  2. | Forward'
  3. | Turn
  4. | Save
  5. | Restore
  6. | Color

The type of orders always accepted by a turtle.

val orders : (string * (orders * int)) list

Mapping from string tokens to orders. Also contains the arity of the orders.

type 'a turtle = {
  1. get_pos : unit -> pos;
    (*

    Get the curent position of the turtle.

    *)
  2. get_color : unit -> color;
    (*

    Get the curent color of the turtle.

    *)
  3. turn : float -> unit;
    (*

    turn a turn the turtle by a degrees.

    *)
  4. move : ?trace:bool -> float -> unit;
    (*

    move ~trace d will move the turtle by d unit. A line should be traced only if trace is true. It's up to the graphical implementation to respect this.

    *)
  5. save_position : unit -> unit;
    (*

    Save the position of the turtle in the stack.

    *)
  6. restore_position : unit -> unit;
    (*

    Restore the position of the turtle from the stack.

    • raises Empty_Stack

      if the stack is empty.

    *)
  7. color : color -> unit;
    (*

    Apply a color for the next drawings.

    *)
  8. handle_lsys : (unit -> unit) -> 'a;
    (*

    Take a function with drawing side effects, handle the bureaucracy before executing it.

    *)
}

Class representing a turtle.

val turtle : unit -> unit turtle

This turtle implements most movement calculations, without any actual drawing. See LisCairo and LisTyxml for use examples. See turtle for methods documentation.

val transform_rhs : 'a turtle -> string -> ('c -> float) array -> 'c -> unit

Can be combined with Lilis.Engine.map_crules to use Lilis.Engine.eval_iter_lsys.

val transform_lsys : 'a turtle -> (string * 'b) Lilis.lsystem -> (('c -> float) array -> 'c -> unit) Lilis.lsystem

Can be feeded directly to Lilis.Engine.eval_iter_lsys.

OCaml

Innovation. Community. Security.