pyp5js icon indicating copy to clipboard operation
pyp5js copied to clipboard

Another Processing.py compatibility hack: keyPressed and mousePressed as variables

Open villares opened this issue 5 years ago • 1 comments

I think we achieved a lot in terms of compatibility with Processing Python mode, so let's please have a look on making keyPressed and mousePressed work as aliases for keyIsPressed and mouseIsPressed.

This might require some gymnastics to make sure mousePressed() and keyPressed() event functions are properly taken care of (p5js bindings) before the sketch actually runs, but I think it won't be a big deal.

villares avatar May 23 '20 13:05 villares

Proof of concept:

class BoolFuncKP():
    def __bool__(self):
        return keyIsPressed
    def __call__(self):
        background(0) # instead of this
        # here we should call the user defined keyPressed() function
        
keyPressed = BoolFuncKP()


def setup():
    size(400, 400)
    
def draw():
    background(240)
    if keyPressed:
        keyPressed()
        fill(255)
    else:
        fill(0)
    rect(100, 100, 100, 100)

villares avatar Mar 03 '21 15:03 villares