-
Notifications
You must be signed in to change notification settings - Fork 4
Description
So ever since Peterc first introduced this gem to me, I thought it was really neat, but I could never get it to work on my platfrom due to the status of the tk package on windows and linux. It must work much nicer on macs? I would like to humbly propose we implement the canvas in HTML5 in the case that the TK package isn't accessible.
How about this:
- In the gemspec, we conditionally require tk, but failing that we require HTML5 deps (so
bundle installand tests can run for non-tk users) - In the Gem itself, we require 'tk' and failing that, we instantiate a 1:1 compatible interface that draws to an HTML5 canvas instead of TK (so alternative TkRoot, TkCanvas, TkcLine, TkcOval, TkTimer, TkSleep static methods are loaded)
Now you're probably wondering at this point, "How is old Notary Sojac going to draw to an HTML5 canvas in a ruby library." And that is where it gets tricky, but not too tricky.
Rendering to an HTML Canvas instead of a TK Canvas
Architecture
- When we start trtl, it will actually boot some web app stuff in child threads (assuming TK isn't available)
** Sinatra will begin listening on port 4567.
** Faye, my websocket server of choise will start listening on 9696
** Sinatra will serve a page containing some javascript that will connect to faye on 9696
System Flow
- From within the existing ruby code, when we call, say, TkRoot, that will actually send data to faye, such that any active javascript clients will be notified of a graphics call
- Then in javascript, any commands such as TkRoot will call the javascript-native functionality to, in this case, create a canvas element on the HTML page.
- All commands sent over faye will be cached and made available to Faye, such that when the user closes there browser to 127.0.0.1:4567 and reopens it, they will see the data they left off with.
What do you think? This proposal is minimally invasive (requires only the addition of lines of code: an extra .rb file tucked away, Gemfile, Gemspec, require conditionality, etc). If you're really excited about the idea, we can re-write the Tk* function calls to Canvas* calls and upon initialization, define what Canvas* translates to (either the actual TK library commands or the ruby commands that delegate that same functionality to javascript).
P.S.
Peter, I tried to get a hold of you over email, but looks like you're enjoying the summer holiday. I hope you're having a good time in Sweden! Maybe we can touch base when you get back? I'll gently spam you another email when you're back to your routine. Also is it possible for folks to arrange for a seat at your App Academy lectures?