Skip to content

Instantly share code, notes, and snippets.

@takawo
Created October 20, 2015 22:10
Show Gist options
  • Save takawo/85f42bc761806884d77e to your computer and use it in GitHub Desktop.
Save takawo/85f42bc761806884d77e to your computer and use it in GitHub Desktop.
PVector a, b, as, bs;
void setup() {
size(960, 540, P2D);
smooth();
colorMode(HSB, 360, 100, 100);
blendMode(ADD);
a = new PVector(200, 200);
b = new PVector(400, 300);
as = new PVector(random(10)-5, random(10)-5);
bs = new PVector(random(10)-5, random(10)-5);
}
void draw() {
background(0, 0, 0);
rect(a.x, a.y, 100, 100);
rect(b.x, b.y, 100, 100);
if (a.x <= b.x +100 && b.x <= a.x +100 && a.y <= b.y +100 && b.y <= a.y +100) {
as.mult(-1);
bs.mult(-1);
}
a.add(as);
b.add(bs);
if (a.x < 0 || a.x + 100 > width) {
as.x *= -1;
}
if (b.x < 0 || b.x + 100 > width) {
bs.x *= -1;
}
if (a.y < 0 || a.y + 100 > height) {
as.y *= -1;
}
if (b.y < 0 || b.y + 100 > height) {
bs.y *= -1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment