android

CC-licensed Ruboto presentation…

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.

Pre-rendered HTML

Source (for Showoff presentation software)

These are Creative Commons-licensed, so you’re encouraged to steal these slides for use at your favorite technology user groups!

android
development
ruby

Permalink

Live-Coding Lessons Learned

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”.)

def save_preset
    t = Time.new
    file_name = sprintf("%04d-%02d-%02d_%02d%02d%02d", t.year, t.month, t.day, t.hour || 0, t.min || 0, t.sec || 0)
    File.open(File.join(preset_directory, file_name), "w") do |file|
        file.print YAML.dump [source_factories, @assigned_factories]
    end
    file_name
end
def next_preset
    directory = Dir.open(preset_directory)
    files = directory.entries[2..-1]
    @preset_index = @preset_index ? @preset_index + 1 : 0
    @preset_index = 0 if @preset_index > files.length - 1
    path = File.join(preset_directory, files[@preset_index])
    source_factories, @assigned_factories = YAML.load_file(path)
    path
end

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.

screen-2010-09-18-at-12412-am.png

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

Continue Reading »

android
development
ruby

Permalink

Networked Drawing Canvas in DRb

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

Here’s our (tiny) sample client:

require 'drb'
DRb.start_service
canvas = DRbObject.new(nil, "druby://192.168.0.100:9000")
canvas.circle(300, 400)

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?

android
development
ruby

Permalink

Ruboto On Acid - Multitouch

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.

Continue Reading »

android
development
ruby

Permalink

Ruboto On Acid…

After dissecting the demos that come with Ruboto 0.2 and figuring out how to upload a library and runner script to an Android emulator (hint: “$ adb push . /sdcard/jruby/subdirname”), it only took an hour or so to create a working Ruby On Acid demo. And what worked on the emulator immediately worked when uploaded to the phone.

Ruby On Acid in Ruboto IRB
Continue Reading »

android
development
ruby

Permalink