Created
November 19, 2014 03:23
-
-
Save shiffman/06fa437f055dccfcc7b3 to your computer and use it in GitHub Desktop.
Algorithm for altering the saturation of a single color. (not using HSB mode).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| color col; | |
| void setup() { | |
| size(200, 100); | |
| col = color(50, 100, 25); | |
| } | |
| void draw() { | |
| background(0); | |
| noStroke(); | |
| fill(col); | |
| rect(0, 0, 100, 100); | |
| float sat = map(mouseX,0,width,0,500); | |
| float r = red(col); | |
| float g = green(col); | |
| float b = blue(col); | |
| float r1 = r; | |
| float g1 = g; | |
| float b1 = b; | |
| float ry1 = (( 70*r1-59*g1-11*b1)/100); | |
| float by1 = ((-30*r1-59*g1+89*b1)/100); | |
| float gy1 = ((-30*r1+41*g1-11*b1)/100); | |
| float y = ( 30*r1+59*g1+11*b1)/100 ; | |
| float ry = (ry1*sat)/100; | |
| float gy = (gy1*sat)/100; | |
| float by = (by1*sat)/100; | |
| r1 = ry + y; | |
| g1 = gy + y; | |
| b1 = by + y; | |
| r1 = constrain(r1, 0, 255); | |
| g1 = constrain(g1, 0, 255); | |
| b1 = constrain(b1, 0, 255); | |
| r = r1; | |
| g = g1; | |
| b = b1; | |
| fill(r,g,b); | |
| rect(100,0,100,100); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment