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

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).

No comments:

Post a Comment

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