Mouse Color Worm
mouse
p5js
sketch
The worm grows randomly, but the color is based on the mouse position. By using HSB (Hue, Saturation, Brightness) color space, the user can control the color of the worm by moving the mouse.
During setup we need to switch to HSB color space with a maximum value of 1.0 for each component:
colorMode(HSB, 1.0);
Then in the draw function, scale the mouseX
and mouseY
values to set the color of the worm.
= color(mouseX / width,
c / height,
mouseY 1.0)
fill(c);