Processing Practice #03 | Event
Contents
- Event
- Mouse Event
- Keyboard Event
Event
Event is a kind of special functions that runs in specific timing interrupting current operation.
Mouse Event
- void mousePressed(){}
- void mouseReleased(){}
- void mouseDragged(){}
- void mouseClicked(){}
- void mouseWheel(){}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | int h,s; boolean pt; void setup(){ size( 500 , 500 ); colorMode(HSB, 100 ); strokeWeight( 10 ); h = 0 ; s = 0 ; pt = false ; } void draw(){ background(h,s, 100 ); if (pt){point(mouseX,mouseY);} } void mousePressed(){ if (mouseButton == LEFT){stroke( 0 , 100 , 50 );} if (mouseButton == RIGHT){stroke( 50 , 100 , 50 );} pt = true ; } void mouseReleased(){ pt = false ; } void mouseDragged(){ s = s+ 1 ; if (s> 100 ){s= 0 ;} } void mouseWheel(MouseEvent event){ h = abs(h + event.getCount()/ 10 ); if (h> 100 ){h= 0 ;} } |
Keyboard Event
- void keyPressed(){}
- void keyReleased(){}
Check Processing Reference for key code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | int col; void setup() { size( 500 , 500 ); col = 127 ; } void draw() { background(col); } void keyPressed() { if (key == 'b' ) { col = 0 ; } if (key == 'w' ) { col = 255 ; } } |