From b9bd58f34bc19dfafecb5f5e86fd8d2598709e48 Mon Sep 17 00:00:00 2001 From: Felix Pankratz Date: Fri, 13 Dec 2024 21:59:56 +0100 Subject: [PATCH] playing around, agents are now stored in a vector --- organism/src/main.cpp | 61 +++++++++++++++++++++++++++++-------------- 1 file changed, 42 insertions(+), 19 deletions(-) diff --git a/organism/src/main.cpp b/organism/src/main.cpp index 107f61b..037f253 100644 --- a/organism/src/main.cpp +++ b/organism/src/main.cpp @@ -5,6 +5,8 @@ #include "main.h" #include "overlay.h" +#include + #define R1 42 #define G1 40 #define BL1 41 @@ -34,18 +36,20 @@ MatrixPanel_I2S_DMA *matrix = nullptr; -#define NUM_AGENTS 128 +//#define NUM_AGENTS 300 //#define AGENT_MOVE_DISTANCE 1 -#define AGENT_DROP_AMOUNT 1 +#define AGENT_DROP_AMOUNT 1 //5 //#define AGENT_ANGLE 0.175 #define NUM_ITERATIONS 1000 -typedef struct { +struct SlimeAgent { int x_position; int y_position; float heading; -} SlimeAgent; +}; + +int NUM_AGENTS; int AGENT_MOVE_DISTANCE; float AGENT_SENSOR_DISTANCE; float AGENT_MOVE_ANGLE; @@ -53,7 +57,8 @@ float AGENT_SENSOR_ANGLE; float attractant[PANEL_WIDTH][PANEL_HEIGHT] = {}; int iterations = 0; -SlimeAgent agents[NUM_AGENTS]; +//SlimeAgent agents[NUM_AGENTS]; +std::vector agents; void init_attractant() { memset(attractant, 0.0, sizeof attractant); @@ -70,7 +75,7 @@ void init_attractant() { // 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; + // attractant[x][y] = 255.0; // } // } //} @@ -78,10 +83,21 @@ void init_attractant() { void init_agents() { AGENT_MOVE_DISTANCE = 1; //random(1, 3); - AGENT_MOVE_ANGLE = random(0, 334) / 1000.0; - AGENT_SENSOR_ANGLE = random(0, 334) / 1000.0; + //AGENT_MOVE_ANGLE = random(0, 334) / 1000.0; + AGENT_MOVE_ANGLE = 0.175;//random(0, 334) / 1000.0; + //AGENT_SENSOR_ANGLE = random(0, 334) / 1000.0; + if (random(0, 2) > 0) { + AGENT_SENSOR_ANGLE = 0.175; + } else { + AGENT_SENSOR_ANGLE = 0.0875; + } + //AGENT_SENSOR_DISTANCE = random(100, 400) / 1000.0; - AGENT_SENSOR_DISTANCE = random(3000, 5000) / 1000.0; + //AGENT_SENSOR_DISTANCE = random(3000, 5000) / 1000.0; + AGENT_SENSOR_DISTANCE = random(2000, 3500) / 1000.0; + + NUM_AGENTS = random(64, 301); + agents.clear(); for(int a = 0; a < NUM_AGENTS; a++) { float angle = ((PI * 2) / NUM_AGENTS) * a; //agents[a].x_position = 31 + round(10*sin(angle)); @@ -90,9 +106,14 @@ void init_agents() { //agents[a].x_position = random(12, 52); //agents[a].y_position = random(12, 20); - agents[a].x_position = random(0, 64); - agents[a].y_position = random(0, 32); - agents[a].heading = (random(0, 100) / 100.0) * (PI*2); + agents.push_back({ + random(0,64), + random(0,32), + (random(0, 100) / 100.0) * (PI*2) + }); + //agents[a].x_position = random(0, 64); + //agents[a].y_position = random(0, 32); + //agents[a].heading = (random(0, 100) / 100.0) * (PI*2); } } @@ -170,7 +191,7 @@ void setupGaussianKernel(float* kernel, int width, float sigma) { Serial.printf("%f %f %f\n", kernel[0], kernel[1], kernel[2]); } -#define GAUSS_WIDTH 5 +#define GAUSS_WIDTH 1 #define GAUSS_SIGMA 1.0 #define DECAY_FACTOR 0.9 float first_pass[PANEL_WIDTH][PANEL_HEIGHT]; @@ -217,7 +238,7 @@ void gaussian_blur() { } } -#define BLUR_KERNEL_SIZE 3 +#define BLUR_KERNEL_SIZE 1 void box_blur() { //Serial.println("memset: starting"); memset(first_pass, 0.0, sizeof first_pass); @@ -259,7 +280,8 @@ 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] = (((8.0*attractant[x][y]) + result) / 9.0); + attractant[x][y] = result; } } } @@ -285,11 +307,12 @@ void loop() { if (is_in_bounds(move_x, move_y)) { agents[a].x_position = move_x; agents[a].y_position = move_y; - if (attractant[move_x][move_y] < 254.0) { + if (attractant[move_x][move_y] < 255.0 - AGENT_DROP_AMOUNT) { attractant[move_x][move_y] += AGENT_DROP_AMOUNT; } } else { - agents[a].heading += (random(-1,2) *2 - 1 ) * 30 / 100.0 * PI*2; + agents[a].heading = (random(0, 100)/100.0) * (PI*2); + // agents[a].heading = (2*PI) - agents[a].heading;//(random(0, 100)/100.0) * (PI*2); } } // sample step @@ -315,9 +338,9 @@ void loop() { } } iterations++; - if (iterations > 64 && iterations % 64 == 0) { // (( == 0) { - //gaussian_blur(); + if (iterations % 4 == 0) { //64 && iterations % 64 == 0) { // (( == 0) { //box_blur(); + //gaussian_blur(); ; } if (iterations >= NUM_ITERATIONS) {