Skip to content

Instantly share code, notes, and snippets.

@thatpixguy
Created September 17, 2013 11:23
Show Gist options
  • Save thatpixguy/6593031 to your computer and use it in GitHub Desktop.
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).
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