[R] Turtle world
baud-bovy.gabriel at hsr.it
Sun Sep 28 21:45:20 CEST 2003
I am trying to do a "loose" implementation in R of the Turtle World (LOGO) and
need some advices on graphical issues.
In its current very simple implementation, the user can give order to the
the turtle to
move through the console. The current position and movements are displayed
graphically (see below). In the future, I would like to permit the turtle
with objects (walls, light source, another turtle, etc.) in the world.
Right now, I am using the windows device and standard plotting functions:
- plot.new() and plot.window() for setting up and clearing the world
- segments() to plot a line representing the displacement of the turtle
- polygone(x,y,border) to plot the turtle
Before the turtle is moved, I "erased" it by calling polygon with
redrawing it with another call to polygon with border=1. The problem with
is that it "erases" also any line already drawn under the turtle. To solve
this problem, I
have considered the following approaches:
- redraw the world each time the turtles moves (this would mean that I have
acess to the
display list or that I manage one). I believe that this might be possible
with the grid package
but I am not sure if this is the best option.
- if I could have access to the internal buffer that corresponds to the
window, I could store (or XrOR) the
section of the buffer when I draw the turtle to restore it when the turtle
Ideally, the approach should be take into account possible development of
the turtle world. For
example, if the turtle world is represented by a matrix (bitmap), I could
use image() (or the
package pixmap) do display it but it is quite slow to draw the entire
world each time the
world changes (e.g., the turtle move). I would also need to define a new
"line" function that would
draw the displacement of the turtle in the world.
Alternatively, objects and turtle's movements could be represented by
display lists. But I
would have to define functions to do the rendering as well as to find out
when the turtle
"intersect" with the object.
Is there any R package (tcl/tk, grid, RGL) that can be adapted to my needs?
Is there R a package
that does 2D graphics? If I need to do some programming in C, is there
anything I could use as a
starting point? Any idea, comment would be most welcome.
More information about the R-help