how to listen the mouse wheel in processing


/ Published in: Processing
Save to your folder(s)

This is the way for listen the mouse wheel and interact from it in processing, enjoy


Copy this code and paste it in your HTML
  1. //////////////////////////////////////////////////////////
  2. //Code By cgiles
  3. //Description : how to add mouse wheel interactivy
  4. //////////////////////////////////////////////////////////
  5. // default size of my ellipse
  6. int tailleEllipse=100;
  7. void setup(){
  8. size(640,480);
  9. frameRate(30);
  10. // this will add a new event listener to your sketch
  11. // for listen how the mouse scroll is used
  12. addMouseWheelListener(new java.awt.event.MouseWheelListener() {
  13. public void mouseWheelMoved(java.awt.event.MouseWheelEvent evt) {
  14. mouseWheel(evt.getWheelRotation());
  15. }});
  16. }
  17. void draw(){
  18. background(255);
  19. ellipse(width/2,height/2,tailleEllipse,tailleEllipse);
  20. }
  21. // this is the event listener of mouse wheel
  22. void mouseWheel(int delta) {
  23. // add the value of wheel's scolling to my ellipse's size
  24. // for a better effiency i multiply the scrolling value by 5
  25. tailleEllipse+=delta*5;
  26. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.