diff --git a/organism/src/main.cpp b/organism/src/main.cpp index 8bd7c2e..ee05d84 100644 --- a/organism/src/main.cpp +++ b/organism/src/main.cpp @@ -3,6 +3,7 @@ #include #include "main.h" +#include "overlay.h" #define R1 42 #define G1 40 @@ -57,6 +58,16 @@ void init_attractant() { // int y = 15 + round(10 * cos(angle)); // attractant[x][y] = 15.0; //} + + // draw a bitmap + //for(int x = 0; x < PANEL_WIDTH; x++) { + // for(int y = 0; y < PANEL_HEIGHT; y++) { + // int pixel_num = (y * PANEL_WIDTH) + x; + // if(overlay[ pixel_num / 8 ] & (1 << (7 - (pixel_num % 8)) ) ){ + // attractant[x][y] = 15.0; + // } + // } + //} } void init_agents() { @@ -150,16 +161,17 @@ void setupGaussianKernel(float* kernel, int width, float sigma) { #define GAUSS_WIDTH 5 #define GAUSS_SIGMA 1.0 -#define DECAY_FACTOR 0.95 +#define DECAY_FACTOR 0.9 +float first_pass[PANEL_WIDTH][PANEL_HEIGHT]; void gaussian_blur() { float kernel[GAUSS_WIDTH]; - uint8_t first_pass[PANEL_WIDTH][PANEL_HEIGHT]; - memset(first_pass, (uint8_t) 0, sizeof first_pass); + // first_pass[PANEL_WIDTH][PANEL_HEIGHT]; + memset(first_pass, 0.0, sizeof first_pass); setupGaussianKernel(kernel, GAUSS_WIDTH, GAUSS_SIGMA); // horizontal pass for (int x = 0; x < PANEL_WIDTH; x++) { for(int y = 0; y < PANEL_HEIGHT; y++) { - float sum = attractant[x][y] * kernel[0]; //0.0; + float sum = attractant[x][y] * DECAY_FACTOR * kernel[0]; //0.0; int additions = 1; for (int x_offset = 1; x_offset < GAUSS_WIDTH; x_offset++) { if (is_in_bounds(x+x_offset, y)) { @@ -171,7 +183,7 @@ void gaussian_blur() { additions++; } } - first_pass[x][y] = (int) round(sum/GAUSS_WIDTH * DECAY_FACTOR); + first_pass[x][y] = sum/GAUSS_WIDTH; } } // vertical pass @@ -189,13 +201,12 @@ void gaussian_blur() { additions++; } } - attractant[x][y] = (sum/GAUSS_WIDTH) * DECAY_FACTOR; + attractant[x][y] = sum/GAUSS_WIDTH; } } } #define BLUR_KERNEL_SIZE 3 -float first_pass[PANEL_WIDTH][PANEL_HEIGHT]; void box_blur() { //Serial.println("memset: starting"); memset(first_pass, 0.0, sizeof first_pass); @@ -204,7 +215,7 @@ void box_blur() { for (int x = 0; x < PANEL_WIDTH; x++) { for(int y = 0; y < PANEL_HEIGHT; y++) { float sum; - sum = attractant[x][y]; //0.0; + sum = attractant[x][y] * DECAY_FACTOR; //0.0; int additions = 1; for (int x_offset = 1; x_offset < BLUR_KERNEL_SIZE; x_offset++) { if (is_in_bounds(x+x_offset, y)) { @@ -238,13 +249,13 @@ void box_blur() { float result = (sum/additions); // * DECAY_FACTOR; //Serial.printf("result: %f", result); //additions: %d\n", sum, additions); attractant[x][y] = (((8.0*attractant[x][y]) + result) / 9.0); - attractant[x][y] = attractant[x][y] * DECAY_FACTOR; } } } void loop() { matrix ->flipDMABuffer(); + delay(10); //matrix->clearScreen(); matrix->fillScreenRGB888(15, 0, 10); @@ -289,7 +300,6 @@ void loop() { agents[a].heading += AGENT_ANGLE * (PI * 2); } } - delay(10); iterations++; if (iterations > 64 && iterations % 64 == 0) { // (( == 0) { //gaussian_blur(); diff --git a/organism/src/overlay.h b/organism/src/overlay.h new file mode 100644 index 0000000..f87ab77 --- /dev/null +++ b/organism/src/overlay.h @@ -0,0 +1,19 @@ +const unsigned char overlay [] PROGMEM = { + // 'bw2, 64x32px + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, + 0x01, 0xf8, 0x00, 0x00, 0x00, 0x1c, 0x03, 0x80, 0x01, 0xfe, 0x00, 0x00, 0x00, 0x1c, 0x03, 0x80, + 0x01, 0xff, 0x00, 0x00, 0x00, 0x1c, 0x03, 0x80, 0x01, 0xc7, 0x80, 0x00, 0x00, 0x1c, 0x00, 0x00, + 0x01, 0xc3, 0x80, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x01, 0xc3, 0x8f, 0xe1, 0xbe, 0x1c, 0x7b, 0x80, + 0x01, 0xc3, 0x8f, 0xe1, 0xff, 0x1c, 0x73, 0x80, 0x01, 0xc3, 0x88, 0x71, 0xe7, 0x1c, 0xe3, 0x80, + 0x01, 0xc3, 0x80, 0x71, 0xc3, 0x9d, 0xe3, 0x80, 0x01, 0xff, 0x00, 0x71, 0xc3, 0x9d, 0xc3, 0x80, + 0x01, 0xff, 0x03, 0xf1, 0xc3, 0x9f, 0x83, 0x80, 0x01, 0xfc, 0x0f, 0xf1, 0xc3, 0x9f, 0xc3, 0x80, + 0x01, 0xc0, 0x1f, 0x71, 0xc3, 0x9f, 0xc3, 0x80, 0x01, 0xc0, 0x3c, 0x71, 0xc3, 0x9d, 0xe3, 0x80, + 0x01, 0xc0, 0x38, 0x71, 0xc3, 0x9c, 0xe3, 0x80, 0x01, 0xc0, 0x38, 0x71, 0xc3, 0x9c, 0xf3, 0x80, + 0x01, 0xc0, 0x1c, 0xf1, 0xc3, 0x9c, 0x73, 0x80, 0x01, 0xc0, 0x1f, 0xf1, 0xc3, 0x9c, 0x7b, 0x80, + 0x01, 0xc0, 0x0f, 0xb1, 0x83, 0x9c, 0x3b, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +};