| versions | 0095+ |
|---|---|
| contributors | eskimoblood |
| started on | 2006-09-20 17:01 |
There are some sites, like Color Schemer, ColorBlender, ColorMatch Redux, that offer color palettes in the .act and .cs file format. This little hack will import these files and store the colors in an array.
/** importcolorpaletts taken from http://processinghacks.com/hacks:importcolorpaletts @author Andreas Köberle */ class Palette{ color[] colors; Palette(String file){ byte[] b=loadBytes(file); if(file.endsWith(".cs")){ createPalette(b,8,26,b[2]&0xff); } else if (file.endsWith(".act")){ createPalette(b,0,3,255); } } Palette(String file, int length){ byte[] b=loadBytes(file); if(file.endsWith(".cs")){ createPalette(b,8,26,length); } else if (file.endsWith(".act")){ createPalette(b,0,3,length); } } void createPalette(byte[] b, int start, int steps, int length){ colors=new color[length]; int cnt=0; for(int i=0 ;i<length;i++){ colors[i]=0xff<<24|b[start+i*steps]<<16|b[start+i*steps+1]<<8|b[start+i*steps+2]; } } } void setup(){ Palette p=new Palette("test.cs"); color cl=p.colors[0]; background(cl); }