Experiments with ruby-processing (processing-2.2.1) and JRubyArt for processing-3.0

Friday 23 August 2013

File Chooser Library For ruby-processing

Well here it is in action my ruby-processing file_chooser library, that like control panel takes a block the fc.display returns a a string that you can use in load_image etc to load a file, you can do all this in a block if you like (see below). Is a replacement for vanilla processing selectInput function that relies on reflection (and the chooser cannot be so easily customised). PS the my_file temporary variable is not required. The chooser starts in the users home folder on unix (mac/linux) or the working directory on windoes.
load_library :file_chooser
attr_reader :img

###########
# Example file chooser (in this case image file chooser)
# the image loading and resizing is encapsulated in the block,
# borrows heavily off control_panel. 
###########

def setup
  size 600, 600
  file_chooser do |fc|
    fc.look_feel "Nimbus"
    fc.set_filter "Image Files",  [".png", ".jpg"]
    my_file = fc.display
    @img = load_image(my_file)
    img.resize(width, height)
  end
end

def draw
  image img, 0, 0
end

The Chooser (a customised JFileChooser)
The Sketch

No comments:

Post a Comment

Followers

Blog Archive

About Me

My photo
I have developed JRubyArt and propane new versions of ruby-processing for JRuby-9.1.5.0 and processing-3.2.2