key_is_down is treated as an event handler, but should just be a callable function
JohnEdChristensen opened this issue · 0 comments
JohnEdChristensen commented
The Sketch
constructor can take key_is_down as an event handler, but in p5js, keyIsDown is a function that takes a keyCode as a parameter, and returns true or false depending if it is currently pressed.
Documentation:
Function source:
processo should just pass this call along to p5js.
Example sketch that does not work:
https://pyscript.com/@johnc14231/proceso-starter-copy-37941/latest
from proceso import Sketch
p5 = Sketch()
p5.describe("A pink circle can moves using 'wasd' or arrow keys.")
def setup():
p5.create_canvas(400, 400)
p5.background("cornflowerblue")
x = y = 0
def draw():
global x, y
p5.background("cornflowerblue")
p5.translate(p5.width * 0.5, p5.height * 0.5)
p5.stroke("white")
p5.fill("deeppink")
speed = 5
if p5.key_is_down(87) or p5.key_is_down(p5.UP_ARROW): # 'W' key
y -= speed
if p5.key_is_down(83) or p5.key_is_down(p5.DOWN_ARROW): # 'S' key
y += speed
if p5.key_is_down(65) or p5.key_is_down(p5.LEFT_ARROW): # 'A' key
x -= speed
if p5.key_is_down(68) or p5.key_is_down(p5.RIGHT_ARROW): # 'D' key
x += speed
p5.circle(x, y, 20)
p5.run_sketch(setup=setup, draw=draw)