Support the event function
hawkingrei opened this issue ยท 4 comments
hawkingrei commented
The event function is call when the event has happen.
the code is inspired by processing.py
value = 0
def draw():
fill(value)
rect(25, 25, 50, 50)
def mouseClicked():
global value
if value == 0:
value = 255
else:
value = 0
gaocegege commented
Only mouseClicked
? Is there any other function or could you give me a link?
It is a good idea ๐
hawkingrei commented
Event function are listed below.
mouseClicked()
mouseDragged()
mouseMoved()
mousePressed()
mouseReleased()
mouseWheel()
keyPressed()
keyReleased()
keyTyped()
jeremydouglass commented
In Processing the interactivity model has two parts:
- built-in variables like mouseX, mouseY, keyPressed, key, and keyCode, which are automatically updated each frame and can be used inside draw().
- event functions like mouseClicked(), keyPressed() etc. (listed above) which are hooks that contain arbitrary code written by the Processing user. Keyboard and mouse events are automatically processed at the end of each draw() frame with calls to the event functions.
For details, see:
https://processing.org/tutorials/interactivity/
The Java reference pages:
mouseClicked()
mouseDragged()
mouseMoved()
mousePressed()
mouseReleased()
mouseWheel()
keyPressed()
keyReleased()
keyTyped()
gaocegege commented
I am on it ๐
value <- 0
draw <- function() {
fill(value)
rect(25, 25, 50, 50)
}
mouseClicked <- function() {
if (value == 0) {
value <- 255
}
else {
value <- 0
}
}