Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| p5js-interaction [2024/02/21 23:46] – renick | p5js-interaction [2024/03/13 07:47] (current) – renick | ||
|---|---|---|---|
| Line 16: | Line 16: | ||
| p5js also has some functions that deal with mouse position relative to the previous frame, including detecting mouse movement, mouse dragging, and whether the left button is pressed. There' | p5js also has some functions that deal with mouse position relative to the previous frame, including detecting mouse movement, mouse dragging, and whether the left button is pressed. There' | ||
| - | ====== tracking the mouse ====== | + | ===== tracking the mouse ===== |
| In the following example, we make a box follow the mouse. | In the following example, we make a box follow the mouse. | ||
| Line 104: | Line 104: | ||
| <iframe src=" | <iframe src=" | ||
| </ | </ | ||
| + | |||
| + | ===== doing something while a key is down ===== | ||
| + | |||
| + | Above, we stored key presses. We can also do something based on whether a certain key is pressed. The keyIsDown function returns either ' | ||
| + | |||
| + | < | ||
| + | <iframe src=" | ||
| + | </ | ||
| + | |||
| + | Read more about the keyIsDown function here: https:// | ||
| + | |||
| + | You can find all of the key codes here: https:// | ||
| + | |||
| + | ===== more about mouse and keyboard in p5js ===== | ||
| + | |||
| + | For more on mouse and keyboard interaction in p5js, see the ' | ||
| ===== using mouse and keyboard events outside of p5js ===== | ===== using mouse and keyboard events outside of p5js ===== | ||
| + | All of these are done with the functions provided by p5js. There is a whole set of keyboard and mouse event handlers built into your browser. You can find more information on them here: | ||
| + | |||
| + | keyboard events: https:// | ||
| + | mouse events: https:// | ||