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

Friday, 26 April 2013

Using ruby 1.9 hash syntax to add sketch options

Previously I posted that the preferred mode for ruby-processing should be "bare" sketches, it works, and is closer to vanilla-processing (processing.js, processing.py and pyprocessing). However it is still possible to write sketches in the original "class mode" with my updated ruby-processing. Here is the full_screen sketch updated for ruby 1.9 hash syntax, works for me.
Just as matter of interest I experimented with building the original ruby-processing with jruby-complete-1.7.3, for some reason only sketches using the default renderer work, I can't be bothered to work out why the 3D sketches fail, but is something to do with the signature of the size/and or render_mode functions...
# Description:
# This is a full-screen demo 
# Since processing-2.0 it is opengl

class MySketch < Processing::App

  def setup
    size @width, @height, P3D

  def draw
    background 0
    fill 120, 160, 220
    (width/100).times do |x|
      (height/100).times do |y|
        new_x, new_y = x * 100, y * 100
        translate new_x + 50, new_y + 50
        rotate_y(((mouse_x.to_f + new_x) / width) * Math::PI)
        rotate_x(((mouse_y.to_f + new_y) / height) * Math::PI)
        box 90


# pass opts as ruby-1.9 hash
MySketch.new full_screen: true, width: 1280, height: 1024

No comments:

Post a Comment


Blog Archive

About Me

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