Camouflage generator (last update: 2013-02-27, created: 2013-02-27) back to the list ↑
Yesterday my brother showed me a camouflage generator he wrote (with a fancy GUI and letting u choose the colors). I decided to give the problem a shot and I've created a short piece of code that generates a raw 32-bit bitmap file that generates a camouflage pattern with some predefined colors and no GUI at all.

Note: the code his horrible (it was coded in ~10 minutes, so no surprise there).

Image examples are below the code.

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <time.h>

#define PTS 1000

#define RES 1024

unsigned int colors[] = {
  0x5a453e00,
  0x544d3e00,
  0x886d5d00,
  0x2d2b2b00
};

struct pt {
  int x, y, c;
} tab[PTS];

unsigned int bmp[RES * RES];

int
main(void)
{
  srand(time(0));
  for(int i = 0; i < PTS; i++) {
    tab[i].x = rand() % RES;
    tab[i].y = rand() % RES;
    tab[i].c = rand() % (sizeof(colors) / sizeof(colors[0]));    
  }

  for(int j = 0; j < RES; j++) {
    for(int i = 0; i < RES; i++) {

      int closet = 0;
      int dx = tab[closet].x - i;
      int dy = tab[closet].y - j;
      int dist = dx * dx + dy * dy;

      // This is slow as hell and there are 1234 ways to make it faster.
      // But whatever ;p
      for(int k = 1; k < PTS; k++) { 
        dx = tab[k].x - i;
        dy = tab[k].y - j;
        int ndist = dx * dx + dy * dy;

        if(ndist < dist) {
          closet = k;   
          dist = ndist;
        }
      }
      
      bmp[i + j * RES] = colors[tab[closet].c];
    }
  }

  FILE *f = fopen("out.raw", "wb");
  fwrite(bmp, 1, sizeof(bmp), f);
  fclose(f);


  return 0;
}


Camo: 1000 points


Camo: 100 points


Camo: 5000 points


Camo: 10000 points


Random note: if you make the color inverse proportional to the distance from a point, you get shiny stars :)
【 design & art by Xa / Gynvael Coldwind 】 【 logo font (birdman regular) by utopiafonts / Dale Harris 】