Selective background colorization? Or coloring null chars in an array?
in
Programming Questions
•
10 months ago
Hi there!
I'm new to Processing, and I've got a question about colorization.
I'm working on a cellular automata program and has different chars (¢, $, etc.) populate to areas of the screen based on a 2D array that calculates a height map. I colorize the chars using a switch function and the fill() command, but I also want to colorize the "background" of certain char
locations on screen so that a non-background color remains even if the char itself changes. I know that using background(r,g,b) is not acceptable since that changes the entire background, but I'm out of ideas. I've pasted the portions of the code for height, color, and char population below.
Any ideas how to do this? Let me know if you need to see more code, as this wont run on it's own.
Char population:
- void setupTerrain(int tx, int ty) {
- if((int)ceil(10*heightMap[tx][ty]) > 10) {
- terrain[tx][ty] = '¶';
- }
- if((int)ceil(10*heightMap[tx][ty]) <= 10) {
- terrain[tx][ty] = '£';
- }
- if((int)ceil(10*heightMap[tx][ty]) <= 7) {
- terrain[tx][ty] = '€';
- }
- if((int)ceil(10*heightMap[tx][ty]) <= 5) {
- terrain[tx][ty] = '$';
- }
- if((int)ceil(10*heightMap[tx][ty]) <= 3) {
- terrain[tx][ty] = '¥';
- }
- if((int)ceil(10*heightMap[tx][ty]) == 0) {
- terrain[tx][ty] = '¢';
- }
- //make water less common
- if((int)ceil(10*heightMap[tx][ty]) < 0) {
- heightMap[tx][ty] *= -1;
- }
- }
Colorization:
- //render
- enemyInfantry = 0;
- playerInfantry = 0;
- background(25,20,25);
- for(int x = 0; x < boardWidth; x++) {
- for(int y = 0; y < boardHeight; y++) {
- //populate display
- display[x][y] = terrain[x][y];
- if(bullets[x][y] != ' ') {
- display[x][y] = bullets[x][y];
- }
- if(infantry[x][y] != ' ') {
- display[x][y] = infantry[x][y];
- }
- //colorize
- switch(display[x][y]) {
- case 'O':
- fill(250,250,250);
- break;
- case 'o':
- fill(240,240,240);
- break;
- case '+':
- fill(230,230,230);
- break;
- case '§':
- fill(250,int(random(130)+100),130);
- break;
- case '½':
- fill(64,64,64);
- break;
- case 'I':
- fill(125,110,45);
- playerInfantry++;
- break;
- case 'l':
- fill(80,115,80);
- enemyInfantry++;
- break;
- case '.':
- fill(250,250,250);
- break;
- case ',':
- fill(250,250,250);
- break;
- case '¤':
- fill(200,50,50);
- break;
- case 'X':
- fill(203,155,106);
- break;
- case '^':
- fill(255,255,255);
- break;
- case '*':
- fill(200,100,50);
- break;
- case '¢':
- fill(117,134,141);
- break;
- case '¥':
- fill(75,68,59);
- break;
- case '$':
- fill(78,78,63);
- break;
- case '€':
- fill(71,85,71);
- break;
- case '£':
- fill(91,111,102);
- break;
- case '¶':
- fill(111,113,115);
- break;
- default:
- fill(63,83,103);
- break;
- }
- text(display[x][y], x*10 + leftMargin, y*11 + topMargin);
- }
- }
1