Created
September 17, 2013 11:23
-
-
Save thatpixguy/6593031 to your computer and use it in GitHub Desktop.
I'm sure I've done this before, so here is some minimal code to generate a HSV colour swatch (in Processing as an example).
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
void setup() { | |
size(256,256); | |
colorMode(RGB,1.0); | |
for(int x=0;x<width;x++) { | |
float h = (float)x/width; | |
float v = 1; | |
for(int y=0;y<width;y++) { | |
float s = (float)y/height; | |
float r = (max(0,min(1,abs(h*2%2-1)*3-1))*s+(1-s))*v; | |
float g = (max(0,min(1,abs(((1-h)+1/3.0)*2%2-1)*3-1))*s+(1-s))*v; | |
float b = (max(0,min(1,abs((h+1/3.0)*2%2-1)*3-1))*s+(1-s))*v; | |
set(x,y,color(r,g,b)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment