loading colors in hex format from a text file
in
Programming Questions
•
2 years ago
I'm trying to load some colors from a text file. It seems like I'm loading the color data successfully, but I can only get them to work for background() - not for fill(). This is the code I'm using:
- int TILE = 8;
- int WIDTH_T = 80; int HEIGHT_T = 40;
- color[] palette;
void setup(){- frameRate(8);
- setpalette();
- size(palette.length*TILE,TILE*5);
- }
void draw() {- background( palette[frameCount % palette.length] );
- drawpalette();
- }
void setpalette() { - String[] strings = loadStrings("pal.txt");
- palette = new color[strings.length];
- for (int p = 0; p<strings.length; p++) {
- palette[p] = color(unhex(strings[p]));
- }
- }
void drawpalette(){ - for (int p = 0; p<palette.length; p++) {
- fill(palette[p]);
- rect(p*TILE, 2*TILE, TILE, TILE);
- //background( palette[frameCount % palette.length] );
- }
- }
- FFFFFF
- 888888
- 000000
- FF0000
- 880000
- 00FF00
- 008800
- 0000FF
- 000088
1