Compare commits
No commits in common. "b9bd58f34bc19dfafecb5f5e86fd8d2598709e48" and "b5a5c9b146d0da3b6da7bb925e4c9cec648165c0" have entirely different histories.
b9bd58f34b
...
b5a5c9b146
@ -5,8 +5,6 @@
|
|||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "overlay.h"
|
#include "overlay.h"
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#define R1 42
|
#define R1 42
|
||||||
#define G1 40
|
#define G1 40
|
||||||
#define BL1 41
|
#define BL1 41
|
||||||
@ -36,20 +34,18 @@
|
|||||||
|
|
||||||
MatrixPanel_I2S_DMA *matrix = nullptr;
|
MatrixPanel_I2S_DMA *matrix = nullptr;
|
||||||
|
|
||||||
//#define NUM_AGENTS 300
|
#define NUM_AGENTS 128
|
||||||
|
|
||||||
//#define AGENT_MOVE_DISTANCE 1
|
//#define AGENT_MOVE_DISTANCE 1
|
||||||
#define AGENT_DROP_AMOUNT 1 //5
|
#define AGENT_DROP_AMOUNT 1
|
||||||
//#define AGENT_ANGLE 0.175
|
//#define AGENT_ANGLE 0.175
|
||||||
#define NUM_ITERATIONS 1000
|
#define NUM_ITERATIONS 1000
|
||||||
struct SlimeAgent {
|
typedef struct {
|
||||||
int x_position;
|
int x_position;
|
||||||
int y_position;
|
int y_position;
|
||||||
float heading;
|
float heading;
|
||||||
};
|
} SlimeAgent;
|
||||||
|
|
||||||
|
|
||||||
int NUM_AGENTS;
|
|
||||||
int AGENT_MOVE_DISTANCE;
|
int AGENT_MOVE_DISTANCE;
|
||||||
float AGENT_SENSOR_DISTANCE;
|
float AGENT_SENSOR_DISTANCE;
|
||||||
float AGENT_MOVE_ANGLE;
|
float AGENT_MOVE_ANGLE;
|
||||||
@ -57,8 +53,7 @@ float AGENT_SENSOR_ANGLE;
|
|||||||
|
|
||||||
float attractant[PANEL_WIDTH][PANEL_HEIGHT] = {};
|
float attractant[PANEL_WIDTH][PANEL_HEIGHT] = {};
|
||||||
int iterations = 0;
|
int iterations = 0;
|
||||||
//SlimeAgent agents[NUM_AGENTS];
|
SlimeAgent agents[NUM_AGENTS];
|
||||||
std::vector<SlimeAgent> agents;
|
|
||||||
|
|
||||||
void init_attractant() {
|
void init_attractant() {
|
||||||
memset(attractant, 0.0, sizeof attractant);
|
memset(attractant, 0.0, sizeof attractant);
|
||||||
@ -75,7 +70,7 @@ void init_attractant() {
|
|||||||
// for(int y = 0; y < PANEL_HEIGHT; y++) {
|
// for(int y = 0; y < PANEL_HEIGHT; y++) {
|
||||||
// int pixel_num = (y * PANEL_WIDTH) + x;
|
// int pixel_num = (y * PANEL_WIDTH) + x;
|
||||||
// if(overlay[ pixel_num / 8 ] & (1 << (7 - (pixel_num % 8)) ) ){
|
// if(overlay[ pixel_num / 8 ] & (1 << (7 - (pixel_num % 8)) ) ){
|
||||||
// attractant[x][y] = 255.0;
|
// attractant[x][y] = 15.0;
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
//}
|
//}
|
||||||
@ -83,21 +78,9 @@ void init_attractant() {
|
|||||||
|
|
||||||
void init_agents() {
|
void init_agents() {
|
||||||
AGENT_MOVE_DISTANCE = 1; //random(1, 3);
|
AGENT_MOVE_DISTANCE = 1; //random(1, 3);
|
||||||
//AGENT_MOVE_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;
|
||||||
//AGENT_SENSOR_ANGLE = random(0, 334) / 1000.0;
|
AGENT_SENSOR_DISTANCE = random(100, 400) / 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(2000, 3500) / 1000.0;
|
|
||||||
|
|
||||||
NUM_AGENTS = random(64, 301);
|
|
||||||
agents.clear();
|
|
||||||
for(int a = 0; a < NUM_AGENTS; a++) {
|
for(int a = 0; a < NUM_AGENTS; a++) {
|
||||||
float angle = ((PI * 2) / NUM_AGENTS) * a;
|
float angle = ((PI * 2) / NUM_AGENTS) * a;
|
||||||
//agents[a].x_position = 31 + round(10*sin(angle));
|
//agents[a].x_position = 31 + round(10*sin(angle));
|
||||||
@ -106,14 +89,9 @@ void init_agents() {
|
|||||||
|
|
||||||
//agents[a].x_position = random(12, 52);
|
//agents[a].x_position = random(12, 52);
|
||||||
//agents[a].y_position = random(12, 20);
|
//agents[a].y_position = random(12, 20);
|
||||||
agents.push_back({
|
agents[a].x_position = random(0, 64);
|
||||||
random(0,64),
|
agents[a].y_position = random(0, 32);
|
||||||
random(0,32),
|
agents[a].heading = (random(0, 100) / 100.0) * (PI*2);
|
||||||
(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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -191,7 +169,7 @@ void setupGaussianKernel(float* kernel, int width, float sigma) {
|
|||||||
Serial.printf("%f %f %f\n", kernel[0], kernel[1], kernel[2]);
|
Serial.printf("%f %f %f\n", kernel[0], kernel[1], kernel[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define GAUSS_WIDTH 1
|
#define GAUSS_WIDTH 5
|
||||||
#define GAUSS_SIGMA 1.0
|
#define GAUSS_SIGMA 1.0
|
||||||
#define DECAY_FACTOR 0.9
|
#define DECAY_FACTOR 0.9
|
||||||
float first_pass[PANEL_WIDTH][PANEL_HEIGHT];
|
float first_pass[PANEL_WIDTH][PANEL_HEIGHT];
|
||||||
@ -238,7 +216,7 @@ void gaussian_blur() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define BLUR_KERNEL_SIZE 1
|
#define BLUR_KERNEL_SIZE 3
|
||||||
void box_blur() {
|
void box_blur() {
|
||||||
//Serial.println("memset: starting");
|
//Serial.println("memset: starting");
|
||||||
memset(first_pass, 0.0, sizeof first_pass);
|
memset(first_pass, 0.0, sizeof first_pass);
|
||||||
@ -280,8 +258,7 @@ void box_blur() {
|
|||||||
|
|
||||||
float result = (sum/additions); // * DECAY_FACTOR;
|
float result = (sum/additions); // * DECAY_FACTOR;
|
||||||
//Serial.printf("result: %f", result); //additions: %d\n", sum, additions);
|
//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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -307,17 +284,13 @@ void loop() {
|
|||||||
if (is_in_bounds(move_x, move_y)) {
|
if (is_in_bounds(move_x, move_y)) {
|
||||||
agents[a].x_position = move_x;
|
agents[a].x_position = move_x;
|
||||||
agents[a].y_position = move_y;
|
agents[a].y_position = move_y;
|
||||||
if (attractant[move_x][move_y] < 255.0 - AGENT_DROP_AMOUNT) {
|
if (attractant[move_x][move_y] < 254.0) {
|
||||||
attractant[move_x][move_y] += AGENT_DROP_AMOUNT;
|
attractant[move_x][move_y] += AGENT_DROP_AMOUNT;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
agents[a].heading = (random(0, 100)/100.0) * (PI*2);
|
agents[a].heading += (random(-1,2) *2 - 1 ) * 30 / 100.0 * PI*2;
|
||||||
// agents[a].heading = (2*PI) - agents[a].heading;//(random(0, 100)/100.0) * (PI*2);
|
|
||||||
}
|
}
|
||||||
}
|
// sample step
|
||||||
// sample step
|
|
||||||
for(int a = 0; a < NUM_AGENTS; a++) {
|
|
||||||
//matrix->drawPixel(agents[a].x_position, agents[a].y_position, matrix->color565(0, 0, attractant[agents[a].x_position][agents[a].y_position]));
|
|
||||||
int front_x = round(agents[a].x_position + cos(agents[a].heading) * AGENT_SENSOR_DISTANCE);
|
int front_x = round(agents[a].x_position + cos(agents[a].heading) * AGENT_SENSOR_DISTANCE);
|
||||||
int front_y = round(agents[a].y_position + sin(agents[a].heading) * AGENT_SENSOR_DISTANCE);
|
int front_y = round(agents[a].y_position + sin(agents[a].heading) * AGENT_SENSOR_DISTANCE);
|
||||||
int left_x = round(agents[a].x_position + cos(agents[a].heading - (AGENT_SENSOR_ANGLE * (PI * 2))) * AGENT_SENSOR_DISTANCE);
|
int left_x = round(agents[a].x_position + cos(agents[a].heading - (AGENT_SENSOR_ANGLE * (PI * 2))) * AGENT_SENSOR_DISTANCE);
|
||||||
@ -338,9 +311,9 @@ void loop() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
iterations++;
|
iterations++;
|
||||||
if (iterations % 4 == 0) { //64 && iterations % 64 == 0) { // (( == 0) {
|
if (iterations > 64 && iterations % 64 == 0) { // (( == 0) {
|
||||||
//box_blur();
|
|
||||||
//gaussian_blur();
|
//gaussian_blur();
|
||||||
|
//box_blur();
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
if (iterations >= NUM_ITERATIONS) {
|
if (iterations >= NUM_ITERATIONS) {
|
||||||
|
Loading…
Reference in New Issue
Block a user