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(){}
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.
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;
}
}
