Mouse Color Worm

mouse
p5js
sketch
Published

November 5, 2018

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.

    c = color(mouseX / width,
              mouseY / height,
              1.0)
    fill(c);