TurtleGraphics icon indicating copy to clipboard operation
TurtleGraphics copied to clipboard

Work inside google colab

Open urrameu opened this issue 9 months ago • 2 comments

Hi,

Would it be possible to make the package work correctly inside google colab? The problem I noticed (there may be others) is that .turtle_undraw() uses grid.remove(), which causes colab to create a new graphic area at every call. I tried to change .turtle_undraw():

.turtle_undraw <- function()
{
   grid.remove("turtle_head", redraw=FALSE)
   grid.remove("turtle_body", redraw=FALSE)
   grid.remove("turtle_leg1", redraw=FALSE)
   grid.remove("turtle_leg2", redraw=FALSE)
   grid.remove("turtle_leg3", redraw=FALSE)
   grid.remove("turtle_leg4", redraw=FALSE)
   invisible(NULL)
}

But this does not remove/undraw the turtle. Eliminating redraw=FALSE from just the last line does remove/undraw the turtle and reduces the number of bogus graphic areas, but that is not a solution.

As a workaround, I eliminated the turtle image completely:

library("TurtleGraphics")
fakedraw <- function() {invisible(NULL)}
environment(fakedraw) <- asNamespace('TurtleGraphics')
assignInNamespace(".turtle_draw",fakedraw, ns="TurtleGraphics")
assignInNamespace(".turtle_undraw",fakedraw, ns="TurtleGraphics")
turtle_init()

which is obviously not great but apparently works ok, at least for simple stuff.

Thanks!

urrameu avatar Mar 19 '25 19:03 urrameu

Thanks! I'll have a look at this when I have more time.

In the meantime, does turtle_hide() do the trick?

gagolews avatar Mar 24 '25 13:03 gagolews

Thanks! I'll have a look at this when I have more time.

In the meantime, does turtle_hide() do the trick?

Unfortunately, no :-(

urrameu avatar Mar 24 '25 14:03 urrameu