Turtle - plot - object

Turtle in LOGO can store variables and execute instructions and functions, it can be called an active object in the programming languages terminology.
Each program in POOL is a function of the #first turtle. This turtle can create child turtles, which can containt their own variables and execute their independent programs (tasks). Functions and variables available to child turtles can be defined as classes.

POOL allows to create a simplified version of a turtle, called simply object. Objects do not have graphics representation and do not handle events related to graphics (e.g. mouse clicks). Objects use less memory, they are created faster and also execute their tasks faster than turtles.

There is one more type of turtle, unique to the POOL dialect: plot. Plot can visualise entire collections of data, using various styles to display values of multi-dimensional vectors. Two spacial global variables are defined for each plots:
   - :data, which is used to store a collection of values to be displayed;
   - :style, which is a dictionary of properties used to draw the plot.
Plots can be displayed in the main or additional graphics window, according to the plot constructor argument. Properties of the graphics window are stored in the shared variables (dictionaries of properties), :pool_cfg and :wndname_canvas_cfg for the main and additional windows respectively (wndname is the name of additional window, as provided to the constructor).

Example 1:

;drawing function:
to spiral :s :c :length
  let "a :c * sign :s
  let "b abs :c
  repeat :length [
    fd :s rt :a
    "a := :a * :b
  ]
  (print who "done)
end

;two child turtles:
"t := newt
"u := newt

;issue instructions on child turtles:
ht @ :t
ht @ :u

;call the drawing function:
(spiral -2 1.006 450) @ :t
(spiral -2 (-1.004) 600) @ :u
spiral 2 0.99 100

Output:

first done
t1 done
t2 done

The above example shows how instructions (ht) and functions (spiral) can be issued on child turtles (:t and :u) without holding the #first turtle's program. The order of text outputs can differ in each trial since turtles are working in parallel.

Example 2:

;class definition for the spiral plots
to spiral :p1 :p2 :deg
  ;function to calculate displayed data
  to fn [:a :p1] [:b :p2]
    ;a list of 2-element arrays will be created,
    ;here is the list constructor and the first item initialization:
    "data := (list array :a 0)

    ;this variable will be a shortcut to :spiral_canvas_cfg
    let "cfg thing word world "_canvas_cfg

    let "t 0 let "s 0.1
    do.while [
      "t += :s
      let "f :a * exp :b * :t
      let "x (sign :deg) * :f * cos :t
      let "y :f * sin :t

      let "p array :x :y
      let "d (distance :p last :data)
      queue :data :p ;add next array to the list

      if :d > 3 ["s := 0.5 * :s]
      if :d < 1 ["s := 2 * :s]
    ] (abs :x < :cfg,"max_x && abs :y < :cfg,"max_y)
  end

  fn ;calculate spiral using constructor parameters :p1 and :p2
  setr 0 ;radius 0 makes the data point symbols hidden
  :style,"mode := "line ;draw lines between data points

  ;timer rotates the plot (data values are not changed)
  "tick := timer [rt :deg] 20
end

;create two plots of the spiral:
"w1 := (newp "Spiral $spiral 2 0.001 (-1)) (setxy 100 0) @ :w1
"w2 := (newp "Spiral $spiral 2 0.001 1) (setxy -100 0) @ :w2

;launch this line in the Commands window:
;(fn 1 0.0002) @ :w1

Output:

Rotating plots of two spirals.

See also:

Classes and inheritance
Synchronization of multiple objects

Table of Content