Recently I've been looking at Povray, pyprocessing, and cfdg (version 3.0) as tools for creating digital images. I have branched two separate blogs where I mainly explore jruby + processing and processing.py

Friday, 14 December 2012

Adding Mouse Wheel Listener to Sketches

This is an interesting one, I've been having difficulty registering a MouseWheelListener from a library in vanilla processing sketches since processing-2.0b7.  However in this simple ruby-processing sketch it was as easy as pie to add a mouse wheel listener, and what is more it still works with my updated ruby-processing that is based on processing-2.0b7.


   1 # mouse_listener.rb
   2 
   3 class JWheelListener
   4   include java.awt.event.MouseWheelListener
   5 
   6   attr_reader :zoom
   7 
   8   def initialize(zoom)
   9     @zoom = zoom
  10   end
  11 
  12   def mouse_wheel_moved(e)
  13     @zoom += e.get_wheel_rotation * 10
  14   end
  15 
  16 end
  17 
  18 attr_reader :wheel
  19 
  20 def setup
  21     size(1000, 1000)
  22     @wheel = JWheelListener.new(10)
  23     self.add_mouse_wheel_listener(@wheel)   
  24 end
  25 
  26 def draw
  27     background 0
  28     fill 255, 0, 0
  29     ellipse(width/2, height/2, wheel.zoom, wheel.zoom)    
  30 end

Of course it all turned out a bit disapointing when I tried it with a 3D sketch, no mouse wheel action.....

Followers

Blog Archive

About Me

My photo
Pembrokeshire, United Kingdom
I have developed JRubyArt and propane new versions of ruby-processing for JRuby-9.1.5.0 and processing-3.2.2