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

Sunday, 12 September 2010

A Mouse Wheel Listener in Ruby Processing

For my 3D context free application/library, I would like to be able to zoom using the mouse wheel, I had vaguely thought about using peasycam or proscene to provide that, and other functionality. In the first instance I wanted to create it myself. After a bit of research, this the sort of implementation I would do using the java classes/interfaces in ruby:-

# mouse_listener.rb

class JWheelListener
  include java.awt.event.MouseWheelListener

  attr_reader :zoom

  def initialize(zoom)
    @zoom = zoom

  def mouse_wheel_moved(e)
    @zoom += e.get_wheel_rotation * 10


class Mouse < Processing::App

  attr_reader :wheel

  def setup
    size(1000, 1000)
    @wheel = JWheelListener.new(10)

  def draw
    background 0
    fill 255, 0, 0
    ellipse(width/2, height/2, wheel.zoom, wheel.zoom)



Mouse.new :title => "Mouse Wheel Listener"

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