Skip to content
jashkenas edited this page Sep 12, 2010 · 11 revisions

Inspired by Nodebox, Ruby-Processing provides a way to control the instance variables of your sketch with a control panel. You can create sliders, buttons, menus and checkboxes that set instance variables on your sketch. Start by loading in the control_panel library, and then define your panel like so:

class PanelTest < Processing::App
  load_ruby_library "control_panel"

  def setup
    control_panel do |c|
      c.slider :opacity
      c.slider(:app_width, 5..60) { reset! }
      c.menu(:options, 'one', 'two', 'three') {|m| load_menu_item(m) }
      c.checkbox :paused
      c.button :reset!
    end
  end

  # Rest of the code follows
end

This code will create a sketch with a control panel for adjusting the value of the @opacity, @app_width, @options, and @paused instance variables. The button will call the reset! method when clicked. The app_width slider will range from 5 to 60 instead of (the default) 0 to 100. The app_width and options controls have had callbacks attached to them. The callbacks will run, passing in the value of the control, any time the control changes. It all looks like this:

(control_panel replaces the previous has_slider functionality)

Clone this wiki locally