In the ants sketch you created an object using OOP called RobotAnt, that you were able to call from your sketch to produce armies of ants that appeared where you clicked. In this sketch you are going to remix the Ants sketch so you can draw with your ant army.
Start by opening your Ants sketch. Go to the file menu and select SAVE AS... Please save your file as Ants Drawing.
The beginning of your code looks similar to the Ants sketch but we are going to use an Array List instead:
int antCount = 10000; //we are going to make 10,000 ants
ArrayList < RobotAnt > antList = new ArrayList();
void setup() {
size(600,600);
background(255);
dave.x = width/2;
dave.y = height/2;
frank.x = width/2;
frank.y = height/2;
for (int i = 0; i < antCount; i++) {
}
}
adding the ants is similar but the color has changed.
void addAnt() {
RobotAnt newbie = new RobotAnt();
newbie.x = mouseX;
newbie.y = mouseY;
// newbie.col = color(random(255), 0, 0, 30); //use this code if you want a gory color
newbie.col = color(0,10); //smoky
antList.add(newbie);
}
The void draw code changes to incorporate the ability to click the mouse or trackpad to "draw" with ants:
void draw() {
if (mousePressed) addAnt();
dave.crawl();
frank.crawl();
for (int i = 0; i < antList.size(); i++) {
antList.get(i).crawl();
}
}
#1 - Medium - Can you get the pile of ants to be a different color EACH time the mouse is pressed?
#2 - Hard - Can you get the pile of ants to be a different color depending on where the mouse is Pressed?