[R] tkcanvas/bitmap for Turtle World

Gabriel Baud-Bovy baud-bovy.gabriel at hsr.it
Wed Oct 15 17:10:40 CEST 2003


To represent a turtle inside a canvas (tcltk package),  I have a serie of 
bitmaps
representing the turtle heading in different directions and I would like
to display the one that corresponds to the current direction of the turtle
(function below).

I have created with Paint a bitmap representing the turtle in BMP format
and succeeded displaying it on canvas after converting it into XBM format
with XBM-BMP utility by Allen Lam :).

However, I have a problem with the rotated versions (rotation done in Adobe
Illustrator and file saved as BMP). When I try to convert the rotated BMP 
into XBM,
the turtle is not centered anymore, its size changes and background becomes 
black.
I know that is not easy to rotate bitmaps but there should be better solution
than Adobe Illustrator (part of the problem might be to know exactly how to 
save it
to keep the same size and appearance).

- does canvas in tcltk support other bitmap formats than BMP on a PC 
(Windows) ?
- is there an utility to rotate bitmap in BMP format (2 colors) working on 
the PC?
(found some for UNIX/LINUX but none on PC).
- is there a simpler way?

Sorry if the question is not exactly R but I am learning to use canvas widget
from tcltk package  (thanks to Barry Rowlings and Damon Wischik for their
replies to my previous post).

Gabriel

Here is my function:

setTurtle<-function(turtle,x,y,angle) {
     if(angle!=turtle$angle) {
        path<-"@c:/Docume~1/Owner/MyDocu~1/MyWork~1/MILAN/UNIHSR/R/turtle_bitmap/"
        # select bitmap file (turtle000.xbm, turtle045.xbm, ...)	
        heading<-(45*(angle*180/pi+22.5)%/%45)%%360
        file<-paste("turtle",paste(rep(0,3-nchar(heading)),collapse=""),heading,".xbm",sep="")
        # redraw
        tkdelete(turtle$canvas,turtle$turtle)
        turtle$turtle<-tkcreate(turtle$canvas,"bitmap",x,y,anchor="center",bitmap=paste(path,file,sep=""))
        turtle$angle <- angle
     }
     if(x!=turtle$x || y!=turtle$y) {
        tkmove(turtle$canvas,turtle$turtle,x-turtle$x,y-turtle$y)
        turtle$x <- x
        turtle$y <- y
     }
     turtle
}
--------------------------------------------------------------------
Gabriel Baud-Bovy
Assistant Professor
UHSR University
via Olgettina, 58	tel:  (+39) 02 2643 4839
20132 Milan, Italy	fax: (+39) 02 2643 4892




More information about the R-help mailing list