070926 | Code, Processing / Java
Tags: Code, hack, input, java, mouse, mousewheel, pde, processing.org
Tags: Code, hack, input, java, mouse, mousewheel, pde, processing.org
Sample code to use mouse wheel events in Processing.
// mouseWheel.pde
// code to use mouse wheel in Processing
// must import java.awt.event.*
import java.awt.event.*;
float y;
void setup() {
size(400,400);
// add mouse wheel listener
frame.addMouseWheelListener(new MouseWheelInput());
y=height/2;
}
void draw() {
background(100);
ellipse(width/2, y, 50,50);
}
// convenience class to listen for MouseWheelEvent
// modify mouseWheelMoved() for your own purposes
class MouseWheelInput implements MouseWheelListener{
void mouseWheelMoved(MouseWheelEvent e) {
int step=e.getWheelRotation();
y=y+step*5;
}
}





Nice!