Gregory - K

By Gregory Batha
//Greg Batha //DESMA 28 Interactivy - exercise K Bot bot1; Bot bot2; void setup(){ size(400,400); background(0); smooth(); noStroke(); bot1 = new Bot(20, 20, 0.02, 0.009, color(255, 0, 0), 0, 2, 20, null); bot2 = new Bot(300, 300, 0.01, 0.0001, color(0, 0, 255), 150, 8, 30, bot1); bot1.otherBot = bot2; ellipseMode(RADIUS); } void draw(){ fill(0, 20); rect(0, 0, width, height); bot1.move(); bot2.move(); } class Bot{ float origSpeed; float speed; float strength; color botColor; //determines distance from which //endX and endY become otherBot's location float aggro; //determines exponent for curve path int shy; float botSize; Bot otherBot; float x; float y; float startX; float startY; float endX; float endY; float pct = 0.0; //constructor Bot(int beginX, int beginY, float botSpeed, float pushPower, color botTint, float aggression, int exponent, float botSizeIn, Bot botIn){ origSpeed = botSpeed; speed = origSpeed; strength = pushPower; botColor = botTint; aggro = aggression; otherBot = botIn; botSize = botSizeIn; startX = beginX; startY = beginY; x = startX; y = startY; endX = random(0, width); endY = random(0, height); shy = exponent; } void move(){ //keeps bot within the screen x = constrain(x, 0, width-botSize); y = constrain(y, 0, height-botSize); //push(); //accelerates (or decelerates) appropriately if a push has occured if(speed > origSpeed){ speed -= 0.001; } else if(speed < origSpeed){ speed += 0.001; } //checks to see if bot is within aggro distance if(dist(x, y, otherBot.x, otherBot.y) < aggro){ pct += speed; endX = otherBot.x; endY = otherBot.y; if(pct < 1.0){ x = startX + (pct * (endX - startX)); y = startY + (pow(pct, shy) * (endY - startY)); push(); } } else { pct += speed; if(pct < 1.0){ x = startX + (pct * (endX - startX)); y = startY + (pow(pct, shy) * (endY - startY)); } else { pct = 0; startX = endX; startY = endY; endX = random(0, width); endY = random(0, height); } } //make an if statement to determine if other bot is within aggro range float angle = atan2(otherBot.y - y, otherBot.x - x); pushMatrix(); // x += speed; // y += speed; translate(x, y); rotate(angle); display(); popMatrix(); } //puts the two bots in a strength battle if they collide void push(){ if (dist(otherBot.x, otherBot.y, x, y) < botSize + otherBot.botSize){ //find difference in strength and adjusts speeds accordingly //if bot is stronger, it will accelerate a little bit to imply pushing if(strength > otherBot.strength){ speed = (strength - otherBot.strength)/4; } //if bot is weaker, it will accelerate a lot to imply being pushed else if(strength < otherBot.strength){ speed = strength - otherBot.strength; } } } void display(){ fill(botColor); ellipse(0, 0, botSize, botSize); fill(255); ellipse(botSize/1.2, 0, botSize/6, botSize/6); } }

One Comment

  1. Ted Batha
    Posted November 8, 2008 at 6:22 pm | Permalink

    Very impressive use of trailing. Also, the balls seem to be playing and interacting. Very well done.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*