processing-r/Processing.R

Support the event function

hawkingrei opened this issue ยท 4 comments

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

Only mouseClicked ? Is there any other function or could you give me a link?

It is a good idea ๐Ÿ‘

In Processing the interactivity model has two parts:

  1. built-in variables like mouseX, mouseY, keyPressed, key, and keyCode, which are automatically updated each frame and can be used inside draw().
  2. 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()

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
    }
}