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:
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
"t := newt
"u := newt
ht @ :t
ht @ :u
(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:
to spiral :p1 :p2 :deg
to fn [:a :p1] [:b :p2]
"data := (list array :a 0)
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
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
setr 0
:style,"mode := "line
"tick := timer [rt :deg] 20
end
"w1 := (newp "Spiral $spiral 2 0.001 (-1)) (setxy 100 0) @ :w1
"w2 := (newp "Spiral $spiral 2 0.001 1) (setxy -100 0) @ :w2
Output:
Rotating plots of two spirals.
See also:
Classes and inheritance
Synchronization of multiple objects
Table of Content