Skip to content
Martin Prout edited this page Nov 19, 2013 · 7 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. Since ruby-processing-2.0 you need to explicitly set the panel visible from the processing sketch (see included examples). Start by loading in the control_panel library, and then define your panel like so:

class PanelTest < Processing::App
  load_library "control_panel"

  def setup
    control_panel do |c|
      c.look_feel "Nimbus"  # since processing-2.1.4 set look and feel (optional, metal by default)
      c.slider :opacity
      c.slider(:app_width, 5..60, 20) { reset! }
      c.menu(:options, ['one', 'two', 'three'], 'two') {|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 (a method defined by you in your sketch). The app_width slider will range from 5 to 60 instead of (the default) 0 to 100. The instance variable will be initialized at 20 when the sketch is loaded. 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

(control_panel replaces the previous has_slider functionality)

Clone this wiki locally