Wednesday, 22 May 2013

Precast to a java object or use an alias method in ruby-processing (for overloaded java methods)


# alias_background.rb 
# 

class Java::ProcessingCore::PApplet
  java_alias :int_background, :background, [Java::int]
  java_alias :image_background, :background, [Java::ProcessingCore::PImage]
end

attr_reader :img, :show, :col_int, :back_image

def setup
  size(640, 360)
  @show = false
  @img = loadImage("test.png") # NB: test.png size should equal frame size
  #@back_image = img.to_java(Java::ProcessingCore::PImage)
end

def draw
  int_background(0)
  # background(0) # warns about ambigious method
  # background(img) if show
  image_background(img) if show # does not warn about ambiguous method
  # int_background(0) if show # uses a precast java object
end

def mouse_pressed
  @show = !show
end

No comments:

Post a Comment