Skip to content

Instantly share code, notes, and snippets.

@takawo
Created October 23, 2015 08:25
Show Gist options
  • Save takawo/76bcdc72d0ecce940d93 to your computer and use it in GitHub Desktop.
Save takawo/76bcdc72d0ecce940d93 to your computer and use it in GitHub Desktop.
PVector p1, p2;
PVector v1, v2;
float d = 5.0;
void setup() {
size(960, 540);
smooth();
frameRate(60);
colorMode(HSB, 360, 100, 100);
p1 = new PVector(random(width), random(height));
p2 = new PVector(random(width), random(height));
v1 = new PVector(5 - random(10), 5-random(10));
v2 = new PVector(5 - random(10), 5-random(10));
background(0, 0, 100);
}
void draw() {
stroke(0, 0, 80);
line(p1.x, p1.y, p2.x, p2.y);
fill(220, 80, 100);
noStroke();
ellipse(p1.x, p1.y, d, d);
ellipse(p2.x, p2.y, d, d);
p1.add(v1);
p2.add(v2);
if(p1.x < 0 || p1.x + d/2 > width){
v1.x *= -1;
}
if(p1.y < 0 || p1.y + d/2 > height){
v1.y *= -1;
}
if(p2.x < 0 || p2.x + d/2 > width){
v2.x *= -1;
}
if(p2.y < 0 || p2.y + d/2 > height){
v2.y *= -1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment