Create Button Press and Key Press Events in p5.js



Creating button-press and key-press events can add more interactive fun to the program. The picture above shows the "Hello" text I wrote using my program. In this program, users can change colors, clear canvas, change stroke weights, and change background colors by pressing buttons and keys. 



https://editor.p5js.org/hh2871/sketches/-sXGieDYf

In the setup function, I set up the background color, the size of the canvas, stroke weight, and filling color first. Besides, I also preset the positions, texts, and event triggers of the four buttons. After this, I defined the functions of each button and the functions of keypress events. The function of fill() is to change colors. The function of strokeWeight() is to change the stroke weight. The function of background() is to change the background color.

Comments

Popular posts from this blog

Scratch Mini-project: Simple MP4 & Remix