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

Showing posts with label surface. Show all posts
Showing posts with label surface. Show all posts

Saturday, 29 August 2015

Changing window / surface dynamically in JRubyArt

Since the changes to processing-3.0 we are able to resize our sketches dynamically:-
def settings
  size(400, 400)
end

def setup
  sketch_title 'Resizable Surface'
  surface.set_resizable(true)
end

def draw
  background(255)
  stroke_weight 4
  line(100, 100, width - 100, height - 100)
end

def key_pressed
  surface.set_size(rand(200..500).floor, rand(200..500).floor)
end

In this sketch "sketch_title" actually calls surface under the hood with another 'set' method but we don't want these ugly get set prefixed methods in ruby do we. I guess I could similary "fix" resizable and convert set_size to sketch_size? And since true is given as default argument to resizable we don't need that either...
def settings
  size(400, 400)
end

def setup
  sketch_title 'Resizable Surface'
  resizable(true)
end

def draw
  background(255)
  stroke_weight 4
  line(100, 100, width - 100, height - 100)
end

def key_pressed
  sketch_size(rand(200..500).floor, rand(200..500).floor)
end
OK a bit more experimentation also works with FX2D, blows up with P2D, but that's the same with vanilla processing (threading error).

Wednesday, 20 May 2015

Bleeding Edge Stuff With Processing-3.0a9

What a JRubyArt sketch might look like with processing-3.0a9, to set title need to set title of surface (which is a protected field), we make this easy by introducing a 'sketch_title' method that does the clever stuff under the hood. Also note size has moved out of setup to settings method (processing does this for you so you don't see it with vanilla processing). Looking good so far with modified 'trefoil' sketch also monjori' shader (latter requires 'k9 run monjori.rb' as expected), all running with jruby-9.0.0.0-pre2. NB without setting a title get some crazy default title like 'org.jruby.proxy.processing.core.PApplet$Proxy1'.
require 'jruby_art'

class Fred < Processing::AppGL
  def setup
    sketch_title 'Fred' # uses surface.setTitle
  end

  def draw
    background 0
    lights
    fill 200, 0, 0
    translate 150, 150
    rotate_x 0.01 * frame_count
    rotate_y 0.02 * frame_count
    box(90, 90, 90)
  end

  def settings
    size 300, 300, P3D
  end
end
# currently can't set sketch title this way use setup method
Fred.new(title: 'Fred')

Followers

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