The Geek ‘n’ Eat group at work had a Pecha Kucha day, and I prepped a quick presentation on learning Ruby/Clojure/Scala/Javascript through koans. (It’s also secretly about flow and how to achieve it in your coding.) I had recently learned how to record audio and export video from Keynote, and applied my newfound knowledge to do a Youtube-ready version:
Here’s the latest version of my Ruboto presentation… An earlier version of these slides was used by Charlie at JRubyConf 2010, and I updated them for my talk at Philly Emerging Tech.
This time, hooked up to Ruby-Processing. I should have logged the factories assigned to each attribute, but didn’t, so the titles are my best guesses as to how they were generated.
Factories chosen are still completely random, so I’m throwing away ten times as many images as I’m keeping. I bet the really mind-blowing stuff will happen when I add a genetic algorithm.
So when scaled to screen dimensions, for example, x and y coordinates can seem to “rebound” off the edges of the screen, or an object can “bounce” back and forth between two colors, or minimum and maximum sizes. The SineFactory did some of this before, but this gives an abrupt reversal of direction instead of a smooth curve (and sometimes the former looks cooler).
Also, I had the ExampleFactory randomly choose an operation and a constraint mode for its component CombinationFactory. Since it only used the defaults before, and since it seems I never use any functionality that isn’t wrapped up in the ExampleFactory, these rather cool features were woefully under-utilized. This should fix that.
Here’s a few sample SVG files, generated with the updated ExampleFactory:
This is cheating at live-coding - I just replayed my re-do buffer in TextMate. I figured the result would be interesting if I ever want to go back and analyze my technique, though.
I had a spectacular time live-coding on a visualizer for the third Desert Bloom PHX party tonight. I learned a few lessons while doing it, though, which I thought I’d share while they’re still fresh in my mind. I’m hoping these will help anyone who needs to supply visuals for parties.
If you’re randomly generating settings, some of them are gonna look like crap. Code up a way to quickly serialize presets to disk that you can switch between when you have an audience. (You probably don’t need a file save dialog, just a save button. Think “that’s pretty, save that” and “load up the next preset, whatever it is”.)
Turn key settings of your visualizer into a Web service or other network service. I made the onscreen text and “next preset” functions (among others) accessible over the network, then used a script on my smartphone as a remote control, leaving me free to roam the room. This also enables something as simple as control from a second terminal window on the same machine.
class <<f
attr_accessor :text, :text_separator, :max_font_size, :min_font_size, :reset_odds, :shape_type, :max_shape_count, :listen_url
attr_accessor :max_size
end
In honor of Why The Lucky Stiff’s contributions to the fun side of the Ruby community, whyday.org includes a challenge to “see how far you can push some weird corner of Ruby”. I can think of few corners of Ruby that are weirder (or more fun) than DRb.
Distributed RuBy (DRb) is, in my opinion, the most underrated portion of the Ruby standard library. It lets you take a Ruby class and network-enable it with almost no additional code (and without modifying the original class). Back in 2006 when I was considering whether to learn Ruby or not, I took one look at DRb and realized that a language that made such things possible was probably a language worth knowing.
I made this screencast to show off how powerful DRb is, and how easy it is to get started. We create a simple drawing canvas in Tk, then use DRb to network-enable it and draw to it from a 4-line client. We finish with a Ruby client that runs on Android via the Ruboto environment. And along the way, we cover a little basic security to help keep you safe (this is a network app, after all).
Here’s the complete code for the server:
require 'tk'
require 'drb'
$SAFE = 1
canvas = TkCanvas.new(:width => 800, :height => 600)
canvas.pack
class RemoteCanvas
def initialize(canvas)
@canvas = canvas
end
def circle(x, y)
TkcOval.new(@canvas, x, y, x + 40, y + 40)
end
end
DRb.start_service("druby://192.168.0.100:9000", RemoteCanvas.new(canvas))
canvas.mainloop
And here’s the complete touchscreen client for Ruboto:
require "ruboto.rb"
confirm_ruboto_version(4, false)
java_import "org.ruboto.embedded.RubotoView"
require 'drb'
DRb.start_service
$activity.start_ruboto_activity "$druby" do
setup_content do
@service = DRbObject.new(nil, "druby://192.168.0.100:9000")
RubotoView.new($druby)
end
handle_touch_event do |event|
@service.circle(event.get_x, event.get_y)
end
end
Enjoy, and of course feel free to post questions and comments below. And if you’re looking for your own way to celebrate WhyDay, why not pick your favorite library and network-enable it?
Ruboto 0.3 added TouchListener to its event handlers. Here’s my experiment with adding multitouch input to the Ruby On Acid demo…
When it starts up (or the factory resets), all attributes are controlled by an ExampleFactory, meaning they’ll randomly be assigned to LoopFactories, SineFactories, RandomWalkFactories, etc. Touch the screen, though, and control of the drawing x/y position will be given to the touchscreen. Touch in a second place, and control of random attributes will go to your second finger: r/g/b channel, opacity, width, or height.
I'm a software developer whose personal motto is to be vicariously lazy: I believe I can make everyone's lives easier through programming. I'm a Ruby and Java developer and have presented at conferences including RubyConf, mountain.rb, and Philly Emerging Tech. I currently maintain several open-source Ruby libraries, which you can find on my GitHub page. You can find me on Twitter as @jaymcgavren.