Hello, I have two random walkers. One of them(AntC) leaves a trail and the other one(AntD) is suppose to pick it up. How can i do this.
AntC [] armyC = new AntC[1];
AntD [] armyD = new AntD[1];
void setup()
{
size(900, 900);
smooth();
for (int i=0; i<armyC.length; i++)
{
armyC [i] = new AntC();
}
for (int i=0; i<armyD.length; i++)
{
armyD [i] = new AntD();
}
}
void draw()
{
background (0);
for (int i=0; i<armyC.length; i++)
{
armyC[i].heading();
armyC[i].display();
armyC[i].transmit();
armyC[i].drawTrail();
}
for (int i=0; i<armyD.length; i++)
{
armyD[i].heading();
armyD[i].draw();
armyD[i].pickTrail();
//armyD[i].transmit();
}
}
class AntC
{
int[][]coordinates = {{0, 2}, {2, 2}, {2, 0}, {2, -2}, {0, -2}, {-2, -2}, {-2, 0}, {-2, 2}, {0, 5}, {5, 5}, {5, 0}, {5, -5}, {0, -5}, {-5, -5}, {-5, 0}, {-5, 5}};
PVector position;
PVector heading;
ArrayList trail;
int dir;
AntC()
{
//size (600, 600);
//background(255);
float a = random(16); // picking a random value
int b = int(a); // converting random value from float to integer
heading = new PVector(width/2+coordinates [b][0], height/2+coordinates [b][1]);
trail = new ArrayList();
}
void heading()
{
float a = random(-2, 2);
int b = int(a);
dir = dir+b;
if (dir == -1)
{
dir = 15;
}
if (dir == 16)
{
dir = 0;
}
heading.x = (heading.x+width)%width;
heading.y = (heading.y+height)%height;
}
void display()
{
heading();
position = heading.get();
heading = new PVector(position.x+coordinates[dir][0], position.y+coordinates[dir][1]);
//stroke (204, 102, 0);
//line (position.x, position.y, heading.x, heading.y);
stroke (255, 255, 0);
fill(255, 255, 0);
ellipse (heading.x, heading.y, 5, 5);
}
void transmit() {
for (int i=0; i<trail.size (); i++) {
if (trail.size() != 0) {
droppings t = (droppings) trail.get(i);
t.paint();
}
}
}
void drawTrail() {
trail.add(new droppings(new PVector(position.x, position.y), 2));
}
}
class AntD
{
int[][]coordinates = {{0, 2}, {2, 2}, {2, 0}, {2, -2}, {0, -2}, {-2, -2}, {-2, 0}, {-2, 2}, {0, 5}, {5, 5}, {5, 0}, {5, -5}, {0, -5}, {-5, -5}, {-5, 0}, {-5, 5}};
PVector positionD;
PVector headingD;
ArrayList trail;
float dia;
int dir;
AntD()
{
//size (600, 600);
//background(255);
dia = 2;
float a = random(16); // picking a random value
int b = int(a); // converting random value from float to integer
trail = new ArrayList();
headingD = new PVector(random(width)+coordinates [b][0], random(height)+coordinates [b][1]);
}
void heading()
{
float a = random(-2, 2);
int b = int(a);
dir = dir+b;
if (dir == -1)
{
dir = 15;
}
if (dir == 16)
{
dir = 0;
}
headingD.x = (headingD.x+width)%width;
headingD.y = (headingD.y+height)%height;
}
void draw()
{
heading();
positionD = headingD.get();
headingD = new PVector(positionD.x+coordinates[dir][0], positionD.y+coordinates[dir][1]);
stroke (0, 255, 0);
line (positionD.x, positionD.y, headingD.x, headingD.y);
stroke (0, 255, 0);
fill (0, 255, 0);
ellipse (headingD.x, headingD.y, 2, 2);
}
void pickTrail()
{
for (int i=0; i<trail.size(); i++) {
droppings Pn = (droppings) trail.get(i);
Pn.paint();
if (dist(headingD.x, headingD.y, 10, 10) <dia) {
trail.remove(i);
dia=dia+1;
}
}
}
}
class droppings {
PVector loc;
float diameter;
droppings (PVector loc_, float dia) {
loc = loc_;
dia = diameter= 2;
}
void paint () {
fill (255);
noStroke();
ellipse(loc.x, loc.y, diameter,diameter);
}
}