sacsilikon.blogg.se

Fade with mousex
Fade with mousex











fade with mousex

Recall that rapid mouse movement increases the distance between the x/y coordinates captured in successive frames. The line() function draws a line between the current and previous frame’s mouse coordinates.

fade with mousex

The stroke() line rotates the stroke colour each new frame. Global sw stroke ( rainbow ) strokeWeight ( sw ) line ( mouseX, mouseY, pmouseX, pmouseY ) rainbow = sw = 7 def draw (): #print('x:%s, y:%s' % (mouseX, mouseY))

FADE WITH MOUSEX CODE

As per the code below: add the two new global variables ( rainbow and sw), comment out the previous draw lines, and add the four new lines at the bottom of the draw. In other words, if the mouseX is equal to the mouseY you know that the mouse hasn’t moved since the last frame. The pmouseX and pmouseY system variables hold the pointer’s x/y position from the previous frame. There will always be a circle in the top-left corner because the pointer is assumed to be at (0,0) until the mouse moves into the display window. The frameRate is relatively slow (20 fps), so rapid mouse movement results in circles distributed at larger intervals. These same values govern the x/y position of each ellipse (circle) drawn. The print function uses the mouseX and mouseY system variables to print the x/y-coordinates to the Console. Run the sketch and move your mouse pointer about the display window. Add the following setup code: def setup (): size ( 600, 600 ) background ( '#004477' ) frameRate ( 20 ) def draw (): print ( 'x:%s, y:%s' % ( mouseX, mouseY )) fill ( '#FFFFFF' ) ellipse ( mouseX, mouseY, 20, 20 ) We’ll combine them all in one playful sketch.Ĭreate a new file and save it as “mouse_toy”. Processing provides five system variables for retrieving mouse attributes.













Fade with mousex