pyp5js
pyp5js copied to clipboard
Another Processing.py compatibility hack: keyPressed and mousePressed as variables
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.
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)