Turtle graphics protocol #93
Labels
No Label
accepted
bug
clj
documentation
enhancement
errors
infrastructure
later
next
now
optimization
proposal
question
research
semantics
syntax
ux
vm
wontfix
No Milestone
No project
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: twc/ludus#93
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
We need a protocol for turtle graphics that can be platform-independent, since we're aiming at SVG, animated canvas in a browser, native 2D graphics, robot turtles, and a 2D plotter. And perhaps more!
Since we'll want to add things arbitrarily over time, including in short order with animations (and possibly without easily synchronizing the Javascript and WASM event loops), we'll need a buffer. (Probably a ring buffer of JSON strings, each of which describes a turtle motion.)
It strikes me we will also want similar protocols for input as well. In approximate order of operations:
Then we can start thinking about animation, input, output, etc.
One quick question here is whether we want a "turtle graphics protocol" or a more general I/O protocol, which starts with turtle graphics. To wit:
What this allows is additional fields, and thus additional protocols to be added to Ludus in the future. (This is obvious, I'm tired, and I don't want to forget what are effectively shower thoughts.)
I like this idea, and there can be many "adapters" for each protocol ... i.e.
turtle_graphics
can be then consumed by a p5js adapter, or an svg adapter, or whatever really. We could supply a few initial adapters, and then also let people write their own.... ?A few thoughts, notes here:
That means, also, that we have three protocols to work with:
stdout
,stderr
Additional protocols will, of course, be added:
General I/O protocol rough draft:
proto: [proto-name, version]
data: ...
Text stream protocol rough draft:
stdin
,stdout
, andstderr
.Turtle graphics protocol rough draft:
["forward", 100]
Next step: list turtle verbs and arguments.
A simple example:
@matt Any thoughts about this?
Two specific hesitations, which I'm happy to bracket for the time being (or quite a while):
We're repeating the "proto" section with every message. On the one hand, that's probably a good idea? On the other hand, it feels wasteful. (This is probably not the first place to worry about waste...)
stdin
,stdout
,stderr
may eventually be superseded by a WASI interface, but for now I think we can usefully do this without having to deal with the whole WASI thing (including v0.1.0 vs v0.2.0, which is kind of a mess). In this case, I think we can forge ahead with this using our simpler, single-text-stream, JSON-encoded protocol between WASM and JS for the time being.Current set of things to do:
apply_command
,render_turtle
, andstate/call
in JS.So: one thing that seems pointed here is that actually, p5 isn't the best option for web graphics. In particular, we'll likely want three canvases on top of one another: a background layer, a path layer, and a turtle layer. We want to be able to change the background colour without erasing all the paths, and to move the turtles without having to redraw all the paths.
p5 doesn't allow this; multiple canvases aren't a thing, there.
I suspect that directly using the canvas API is likely the best bet, rather than using p5.
So: for now, just as I'm thinking this through, I'll wire up a single-shot, static, not-animated p5 adapter that will be a drop-in replacement for Ludus-web. But the next step, an SVG adapter, will actually be much more robust for a bunch of stuff, including print output.
Then, an animated, multi-turtle, actor-model situation will be based on the Canvas API.
I did a whole bunch of this this summer. Static SVG graphics are done. Shifting most of p5 stuff from Ludus/Janet to Javascript is done. CLI is not done, but that's simple-ish, and in any event is not a priority.