Dougal - K

By Dougal Henken
/*This program is based on pacing and human interaction. When people pace, they often become lost in their own thoughts. Their walking becomes a single activity, and the participant becomes unaware of their surroundings. So when they bump into someone, such as another person pacing, they become flustered and lose a little of their direction. Major, major thanks to Greg for helping with motion and object interactivity. */ Block b1; Block b2; void setup(){ size(400, 400); b1 = new Block(70, 293, null, true, 1, color(255, 111, 0)); b2 = new Block(200, 293, b1, false, 2, color(68, 255, 13)); b1.other = b2; } void draw(){ background(255); b1.move(); b1.display(); b2.move(); b2.display(); } class Block{ float x; float y; float currentx; float currenty; boolean vert; int direction; Block other; int speed; color col; Block(float positionx, float positiony, Block otherDancer, boolean vertical, int howFast, color boxColor){ x = positionx; y = positiony; vert = vertical; currentx = x; currenty = y; direction = -1; other = otherDancer; speed = howFast; col = boxColor; } void move(){ if (vert == true) { currenty = constrain(currenty, 0, y); currenty += speed * direction; if (other.currentx + 50 > currentx && other.currentx < currentx + 50 && other.currenty + 50 > currenty && other.currenty < currenty + 50){ currentx += random(-3, 3); } if(currenty == 0 || currenty == y){ direction *= -1; } } else { currentx = constrain(currentx, 0, x); currentx += speed * direction; if (other.currentx + 50 > currentx && other.currentx < currentx + 50 && other.currenty + 50 > currenty && other.currenty < currenty + 50){ currenty += random(-3, 3); } if(currentx == 0 || currentx == x){ direction *= -1; } } } void display() { fill(col); rect(currentx, currenty, 50, 50); } }

Post a Comment

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

*
*