11/* Example for shifting colors.
2+ * Click on a color in the picture to select a color.
3+ * Move the mouse from left to right to see the color shifting.
24 *
35 * Author: Nick 'Milchreis' Müller
46 */
57
68import milchreis.imageprocessing.* ;
79
810PImage image;
9- color blue = #3896F2;
11+ int hue = 0 ;
12+ int x = 0 , y = 0 ;
13+ int shiftedColor = 0 ;
14+ int pixel = 0 ;
1015
1116void setup () {
1217 size (550 , 550 );
@@ -17,13 +22,36 @@ void setup() {
1722void draw () {
1823
1924 if (mousePressed == true ) {
20- image (image, 0 , 0 );
25+ // Select color from clicked position
26+ pixel = image. get(mouseX , mouseY );
27+
28+ // Save mouse position to compare the shifted value
29+ x = mouseX ;
30+ y = mouseY ;
31+
32+ // Get hue value
33+ hue = (int )Tools . rgbToHsb(pixel)[0 ];
34+
2135 } else {
36+ // Get shift by mouse x-axis
2237 int shift = (int )map (mouseX , 0 , width , - 30 , 30 );
23- int hue = ( int ) map ( mouseY , 0 , height , 0 , 360 );
24- // float shift = map(mouseX, 0, width, -0.3, 0.3);
38+
39+ // Shift the selected color by hue value
2540 PImage p = ColorShift . applyHue(image, hue, 10 , shift);
2641
42+ // Get new shifted color
43+ shiftedColor = p. get(x, y);
44+
2745 image (p, 0 , 0 );
2846 }
47+
48+ noStroke ();
49+
50+ // Draw selected color
51+ fill (pixel);
52+ rect (0 , height - 10 , width / 2 , 10 );
53+
54+ // Draw shifted color
55+ fill (shiftedColor);
56+ rect (width / 2 , height - 10 , width / 2 , 10 );
2957}
0 commit comments