CAVEAT: this code attempts to use the mouse wheel, and that doesn't always work so well from an applet depending on your browser, (firefox and safari on Windows both appear to be ok, both IE and Chrome will scroll the page too, annoying). Trying left-clicking inside the applet first before using the mouse wheel, may improve your luck and "capture" the wheel. Note that it does work ok when run standalone outside the browser or from the PDE.
HSBColorSelectorDemo.pde
by: http://www.davebollinger.com
for: http://www.processing.org as of 1.0.1
Purpose: Simple demo use of a run-time HSB color-selection widget.
This widget is intended to roughly mimic the functionality of Photoshop's color picker when the H (hue) radio button is selected. The primary difference is that it updates continuously rather than requiring a click within the Saturation-Brightness grid. (of course, YOUR code can optionally "wait" for a mouse click before USING the value, as demo'd here) It's intended as a lean-mean replacement for quick runtime color selection.
For the purposes of this demo...
Background will track color continuously while widget is visible.
Rectangle will aquire color on left-click while widget is visible.
(again, how/when YOU assign colors in YOUR sketch is up to you)
Right-click mouse or press Space to toggle the widget visibility.
Move mouse within the widget to adjust Saturation (X) and Brightness (Y)
Scroll mouse wheel within the widget to adjust Hue.
Press 'i' to toggle mouse wheel inversion (which direction will increase/decrease hue)
Press 'm' to toggle a marker cursor within the widget.
Press 'v' to toggle numeric value display within the widget.
(both 'm' and 'v' above are performance hits, use judiciously)
General usage in your code:
It's not a compiled library, just a raw .java file, so just copy it
into your sketch folder and reload your sketch. (of course you may
compile it yourself to a library if you'd rather, it's ready to go)
Create an instance like so in your setup() for example:
HSBColorSelector hsbcs = new HSBColorSelector(this);
Display it like so:
hsbcs.show();
...interact with it by mousing around...
Then retrieve the current color like so:
color c = hsbcs.getColor();
The widget will do it's own mouse handling and drawing as necessary when visible. It'll sit quietly dormant in the background doing nothing when hidden.
For other operations refer to the source code, it's pretty simple, and there are probably just barely enough comments to help out where necessary.
Built with Processing