berinhard / pyp5js

Python to P5.js Transcriptor
https://berinhard.github.io/pyp5js/
GNU Lesser General Public License v3.0
200 stars 37 forks source link

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

Closed villares closed 4 months ago

villares commented 4 years ago

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 commented 3 years ago

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 commented 4 months ago

I changed my mind, now I think we should pursue py5 or p5js compatibility, or both, not Processing Python mode, which is dead.