/*//////////////////////////////////
// Interactive Toy //
// Exterminator //
// Austin Waterson //
// Media Computation //
*///////////////////////////////////
//Initializing ant starting positions
//Forcing them to stay within the width
float antPosX = random(5, 395);
float antPosY = random(400, 450);
float antTwoPosX = random(5, 395);
float antTwoPosY = random(400, 450);
float antThreePosX = random(5, 395);
float antThreePosY = random(400, 450);
float antFourPosX = random(5, 395);
float antFourPosY = random(400, 450);
float antFivePosX = random(5, 395);
float antFivePosY = random(400, 450);
//the speed at which the ants will travel
int speed = 3;
void setup()
{
size(400, 400);
}
void draw()
{
drawBackground();
//drawing ants individually based on previously set variables
drawAnt();
drawAntTwo();
drawAntThree();
drawAntFour();
drawAntFive();
//spray can
Spray();
drawSprayCan();
//Detection and movement
updateAnts();
sprayDetect();
}
void drawBackground()
{
background(255);
fill(0, 0, 255);
//Creates checkered pattern
for (int i = 0; i<width*2; i+=50)
{
for (int j = 0; j<=height*2; j+=50)
{
rect(i, j, 50, 50);
j+=50;
}
i+=50;
}
for (int i = 50; i<width*2; i+=50)
{
for (int j = 50; j<=height*2; j+=50)
{
rect(i, j, 50, 50);
j+=50;
}
i+=50;
}
}
void drawSprayCan()
{
stroke(0);
fill(255, 0, 0);
rect(mouseX-8, mouseY-15, 16, 30);
fill(150);
rect(mouseX-2, mouseY-20, 3, 5);
rect(mouseX-3, mouseY-25, 5, 5);
rect(mouseX-10, mouseY+15, 20, 2);
rect(mouseX-10, mouseY-15, 20, 2);
}
void drawAnt()
{
fill(175, 0, 0);
line(antPosX-5, antPosY-5, antPosX+5, antPosY-5);
line(antPosX-5, antPosY, antPosX+5, antPosY);
line(antPosX-5, antPosY+5, antPosX+5, antPosY+5);
ellipse(antPosX, antPosY-5, 5, 5);
ellipse(antPosX, antPosY, 5, 5);
ellipse(antPosX, antPosY+5, 5, 5);
}
void drawAntTwo()
{
fill(175, 0, 0);
line(antTwoPosX-5, antTwoPosY-5, antTwoPosX+5, antTwoPosY-5);
line(antTwoPosX-5, antTwoPosY, antTwoPosX+5, antTwoPosY);
line(antTwoPosX-5, antTwoPosY+5, antTwoPosX+5, antTwoPosY+5);
ellipse(antTwoPosX, antTwoPosY-5, 5, 5);
ellipse(antTwoPosX, antTwoPosY, 5, 5);
ellipse(antTwoPosX, antTwoPosY+5, 5, 5);
}
void drawAntThree()
{
fill(175, 0, 0);
line(antThreePosX-5, antThreePosY-5, antThreePosX+5, antThreePosY-5);
line(antThreePosX-5, antThreePosY, antThreePosX+5, antThreePosY);
line(antThreePosX-5, antThreePosY+5, antThreePosX+5, antThreePosY+5);
ellipse(antThreePosX, antThreePosY-5, 5, 5);
ellipse(antThreePosX, antThreePosY, 5, 5);
ellipse(antThreePosX, antThreePosY+5, 5, 5);
}
void drawAntFour()
{
fill(175, 0, 0);
line(antFourPosX-5, antFourPosY-5, antFourPosX+5, antFourPosY-5);
line(antFourPosX-5, antFourPosY, antFourPosX+5, antFourPosY);
line(antFourPosX-5, antFourPosY+5, antFourPosX+5, antFourPosY+5);
ellipse(antFourPosX, antFourPosY-5, 5, 5);
ellipse(antFourPosX, antFourPosY, 5, 5);
ellipse(antFourPosX, antFourPosY+5, 5, 5);
}
void drawAntFive()
{
fill(175, 0, 0);
line(antFivePosX-5, antFivePosY-5, antFivePosX+5, antFivePosY-5);
line(antFivePosX-5, antFivePosY, antFivePosX+5, antFivePosY);
line(antFivePosX-5, antFivePosY+5, antFivePosX+5, antFivePosY+5);
ellipse(antFivePosX, antFivePosY-5, 5, 5);
ellipse(antFivePosX, antFivePosY, 5, 5);
ellipse(antFivePosX, antFivePosY+5, 5, 5);
}
void Spray()
{
//if the mouse is clicked apply the patter for the spray
if (mousePressed == true)
{
fill(30, 220, 35);
noStroke();
triangle(mouseX-1, mouseY-20, mouseX-30, mouseY-50, mouseX-30, mouseY-20);
ellipse(mouseX-35, mouseY-50, 15, 15);
ellipse(mouseX-45, mouseY-50, 15, 15);
ellipse(mouseX-35, mouseY-35, 30, 30);
ellipse(mouseX-50, mouseY-30, 15, 15);
ellipse(mouseX-48, mouseY-40, 15, 15);
ellipse(mouseX-35, mouseY-25, 15, 15);
}
}
void updateAnts()
{
antPosY-=speed;
antTwoPosY-=speed;
antThreePosY-=speed;
antFourPosY-=speed;
antFivePosY-=speed;
//once an ant hits the top of the screen its position is set randomly below screen
if (antPosY<=0)
{
antPosY = random(400, 450);
antPosX = random(5, 395);
}
if (antTwoPosY<=0)
{
antTwoPosY = random(400, 450);
antTwoPosX = random(5, 395);
}
if (antThreePosY<=0)
{
antThreePosY = random(400, 450);
antThreePosX = random(5, 395);
}
if (antFourPosY<=0)
{
antFourPosY = random(400, 450);
antFourPosX = random(5, 395);
}
if (antFivePosY<=0)
{
antFivePosY = random(400, 450);
antFivePosX = random(5, 395);
}
}
void sprayDetect()
{
//If an ant enters a small 20x30 box within the spray their position is reset randomly
if (antPosX <= mouseX-30 && antPosX >=mouseX-50 && antPosY-20 <= mouseY && antPosY >= mouseY-50)
{
antPosX = random(5, 395);
antPosY = random(400, 450);
}
if (antTwoPosX <= mouseX-30 && antTwoPosX >=mouseX-50 && antTwoPosY-20 <= mouseY && antTwoPosY >= mouseY-50)
{
antTwoPosX = random(5, 395);
antTwoPosY = random(400, 450);
}
if (antThreePosX <= mouseX-30 && antThreePosX >=mouseX-50 && antThreePosY-20 <= mouseY && antThreePosY >= mouseY-50)
{
antThreePosX = random(5, 395);
antThreePosY = random(400, 450);
}
if (antFourPosX <= mouseX-30 && antFourPosX >=mouseX-50 && antFourPosY-20 <= mouseY && antFourPosY >= mouseY-50)
{
antFourPosX = random(5, 395);
antFourPosY = random(400, 450);
}
if (antFivePosX <= mouseX-30 && antFivePosX >=mouseX-50 && antFivePosY-20 <= mouseY && antFivePosY >= mouseY-50)
{
antFivePosX = random(5, 395);
antFivePosY = random(400, 450);
}
}