add random params
This commit is contained in:
parent
d5879e10b3
commit
b5a5c9b146
@ -35,9 +35,10 @@
|
||||
MatrixPanel_I2S_DMA *matrix = nullptr;
|
||||
|
||||
#define NUM_AGENTS 128
|
||||
#define AGENT_MOVE_DISTANCE 1
|
||||
|
||||
//#define AGENT_MOVE_DISTANCE 1
|
||||
#define AGENT_DROP_AMOUNT 1
|
||||
#define AGENT_ANGLE 0.175
|
||||
//#define AGENT_ANGLE 0.175
|
||||
#define NUM_ITERATIONS 1000
|
||||
typedef struct {
|
||||
int x_position;
|
||||
@ -45,6 +46,11 @@ typedef struct {
|
||||
float heading;
|
||||
} SlimeAgent;
|
||||
|
||||
int AGENT_MOVE_DISTANCE;
|
||||
float AGENT_SENSOR_DISTANCE;
|
||||
float AGENT_MOVE_ANGLE;
|
||||
float AGENT_SENSOR_ANGLE;
|
||||
|
||||
float attractant[PANEL_WIDTH][PANEL_HEIGHT] = {};
|
||||
int iterations = 0;
|
||||
SlimeAgent agents[NUM_AGENTS];
|
||||
@ -71,6 +77,10 @@ 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_SENSOR_DISTANCE = random(100, 400) / 1000.0;
|
||||
for(int a = 0; a < NUM_AGENTS; a++) {
|
||||
float angle = ((PI * 2) / NUM_AGENTS) * a;
|
||||
//agents[a].x_position = 31 + round(10*sin(angle));
|
||||
@ -281,23 +291,23 @@ void loop() {
|
||||
agents[a].heading += (random(-1,2) *2 - 1 ) * 30 / 100.0 * PI*2;
|
||||
}
|
||||
// sample step
|
||||
int front_x = round(agents[a].x_position + cos(agents[a].heading) * AGENT_MOVE_DISTANCE);
|
||||
int front_y = round(agents[a].y_position + sin(agents[a].heading) * AGENT_MOVE_DISTANCE);
|
||||
int left_x = round(agents[a].x_position + cos(agents[a].heading - (AGENT_ANGLE * (PI * 2))));
|
||||
int left_y = round(agents[a].y_position + sin(agents[a].heading - (AGENT_ANGLE * (PI * 2))));
|
||||
int right_x = round(agents[a].x_position + cos(agents[a].heading + (AGENT_ANGLE * (PI * 2))));
|
||||
int right_y = round(agents[a].y_position + sin(agents[a].heading + (AGENT_ANGLE * (PI * 2))));
|
||||
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 left_x = round(agents[a].x_position + cos(agents[a].heading - (AGENT_SENSOR_ANGLE * (PI * 2))) * AGENT_SENSOR_DISTANCE);
|
||||
int left_y = round(agents[a].y_position + sin(agents[a].heading - (AGENT_SENSOR_ANGLE * (PI * 2))) * AGENT_SENSOR_DISTANCE);
|
||||
int right_x = round(agents[a].x_position + cos(agents[a].heading + (AGENT_SENSOR_ANGLE * (PI * 2))) * AGENT_SENSOR_DISTANCE);
|
||||
int right_y = round(agents[a].y_position + sin(agents[a].heading + (AGENT_SENSOR_ANGLE * (PI * 2))) * AGENT_SENSOR_DISTANCE);
|
||||
float front_value = attractant[front_x][front_y];
|
||||
float left_value = attractant[left_x][left_y];
|
||||
float right_value = attractant[right_x][right_y];
|
||||
if (front_value > right_value and front_value > left_value) {
|
||||
;
|
||||
} else if (front_value < right_value and front_value < left_value) {
|
||||
agents[a].heading += (random(0, 2) * 2 - 1) * (AGENT_ANGLE / 100.0) * (PI*2) ;
|
||||
agents[a].heading += (random(0, 2) * 2 - 1) * (AGENT_MOVE_ANGLE / 100.0) * (PI*2) ;
|
||||
} else if (left_value > right_value) {
|
||||
agents[a].heading -= AGENT_ANGLE * (PI * 2);
|
||||
agents[a].heading -= AGENT_MOVE_ANGLE * (PI * 2);
|
||||
} else {
|
||||
agents[a].heading += AGENT_ANGLE * (PI * 2);
|
||||
agents[a].heading += AGENT_MOVE_ANGLE * (PI * 2);
|
||||
}
|
||||
}
|
||||
iterations++;
|
||||
|
Loading…
Reference in New Issue
Block a user