From the course: Coding for Visual Learners: Learning JavaScript from Scratch

Unlock this course with a free trial

Join today to access over 24,400 courses taught by industry experts.

MouseX and mouseY

MouseX and mouseY

- [Instructor] p5.js variable mouseX holds the current horizontal position of the mouse. And the mouseY holds the current vertical position. This sounds simple enough, but it has the potential to enable a great deal of user interaction in our programs. So these are incredibly useful variables. If you were to provide these values as X and Y coordinates of a shape, we would essentially be moving that shape as we move our cursor, our mouse on the screen. Let's try using these variables with a simplified version of our program. So to simplify the program, I will get rid of these toggle statements. I will retain the background function. I will get rid of the toggle global variable as well, which we don't need anymore. And I will get rid of the rectangle that is here. I will make my circle a little bit smaller too. Let's make it size 50. And since we don't have the rectangle anymore, we don't require this rectmode function as…

Contents