-- " Brownian - Benjie Reynolds // ######BROWNIAN ##########

// Benjie Reynolds

int xposA = 0;
int yposA = 0;
int xposB = 300;
int yposB = 300;
int speedA = 1;
int speedB = 1;


void setup() {
size(300,300); // Defines window 600 by 600 pixels
framerate(30); // Cycling through 30 frames a second
background(0);

}


void loop() {

if(keyPressed) { //speeds up process
if (key == RIGHT) {
speedA=speedA+1;
speedB=speedB+1;
}
}
if(keyPressed) { //speeds up process
if (key == LEFT) {
speedA=speedA-1;
speedB=speedB-1;
}
}

fill(204, 102, 0); //set up center square
stroke(0);
rect(140, 140, 20, 20); //color in square
int xrand = int(random(2*2 + 1)) - 2;
xrand = xrand * speedA; //adjusts the distance xrand travels
int yrand = int(random(2*2 + 1)) - 2;
yrand = yrand * speedA; //adjusts the distance yrand travels
int oldxA = xposA; //saves value of xposA before it changes
int oldyA = yposA; //saves value of yposA before it changes
xposA = xposA + xrand; //moves xposA randomly between -2 and 2 pixels
yposA = yposA + yrand; //moves yposA randomly between -2 and 2 pixels

if (xposA < 0 || xposA > 300) //for when xposA goes out of bounds on the left side
{
xposA = xposA - xrand; // places xposA one step backwards
}
if (yposA < 0 || yposA > 300) //for when yposA goes out of bounds on the top
{
yposA = yposA - yrand; // places xposA one step backwards
}

// print(xposA +","); //prints location of point "xposA"
// print(yposA + " "); //prints location of point "yposA"
stroke(int(random(256)),int(random(256)),0,75); //set ink to random color
point(xposA,yposA); //draws location on screen
line(oldxA, oldyA, xposA, yposA);
if ((xposA >= 140 && xposA <=160)&&(yposA >= 140 && yposA <=160))
{
xposA = 0;
yposA = 0;
xposB = 300;
yposB = 300;
speedB = speedB + 1; //if line A wins B gets faster
}
//part for line B

xrand = int(random(2*2 + 1)) - 2;
xrand = xrand * speedB; //adjusts the distance xrand travels
yrand = int(random(2*2 + 1)) - 2;
yrand = yrand * speedB; //adjusts the distance yrand travels
int oldxB = xposB; //saves value of xposA before it changes
int oldyB = yposB; //saves value of yposA before it changes
xposB = xposB + xrand; //moves xposA randomly between -2 and 2 pixels
yposB = yposB + yrand; //moves yposA randomly between -2 and 2 pixels

if (xposB < 0 || xposB > 300) //for when xposA goes out of bounds on the left side
{
xposB = xposB - xrand; // places xposA one step backwards
}
if (yposB < 0 || yposB > 300) //for when yposA goes out of bounds on the top
{
yposB = yposB - yrand; // places xposA one step backwards
}

// print(xrand +","); //prints location of point "xposA"
// print(yrand + " "); //prints location of point "yposA"
stroke(0,int(random(256)),int(random(256)),75); //set line to random color
point(xposB,yposB); //draws location on screen
line(oldxB, oldyB, xposB, yposB);
if ((xposB >= 140 && xposB <=160)&&(yposB >= 140 && yposB <=160))
{
xposA = 0;
yposA = 0;
xposB = 300;
yposB = 300;
speedA = speedA + 1; //if line b wins it gets faster
}

}
"