The Repl.it Turtle Mystery
The Problem
I maintain the TeachLA editor, which as one of its core capabilities, is a
Python source file editor that supports
turtle
graphics. turtle
graphics are in essence animations that play on a canvas, where a sprite (in
the shape of a turtle) moves around the screen and strokes a path in
its trail.
Getting the Python code to run isn't too difficult: there are browser
implementations of Python transpiling Python source code to Javascript
like Brython and Skulpt. But because turtle
depends on Tk for rendering, which
is not present in the browser, these implementations each have developed their
own way of rendering turtle
graphics. But none of them have the features I need
most, which is the ability to resize screen without having to replay the entire
animation. This is useful for:
- resizing the editor and canvas panes by dragging the split divider
- hiding the canvas pane temporarily, then displaying it again, already rendered
The Solution (In Theory)
Here's a glimmer of hope: repl.it already has this working on their website:
Notice the delay on resizing. I suspect the turtle graphics are rendered on a server and streamed to the browser (like what this person found in this Stack Overflow post).
The optimal solution, in my opinion, is to run all the Python source code on a server with an actual Python runtime instead of one from the browser. Even though this means the turtle graphics aren't as smooth (since they aren't "native") as Brython and Skulpt, it is still a more robust long term solution.
I am still in the process of contacting repl.it to find out how it's done!
Update (Oct 26)
Some kind folks responded to me here, and it seems a key tool here is X11vnc, which is a facility that would allow streaming of graphics from an X server to a client. This could be used with Apache Guacamole managing the access to the remote server, potentially!
It still would be a lot of work to implement—if you'd like to help, message me!