Skip to content

Instantly share code, notes, and snippets.

@mharju
Created January 3, 2017 18:16
Show Gist options
  • Save mharju/dd1078c66250302b0900b26c7349d9b0 to your computer and use it in GitHub Desktop.
Save mharju/dd1078c66250302b0900b26c7349d9b0 to your computer and use it in GitHub Desktop.
Them circles
class Circle {
PVector center;
float radius;
public Boolean intersects(ArrayList<Circle> circles) {
for(Circle other : circles) {
if(this.center.dist(other.center) <= (other.radius + this.radius)) {
return true;
}
}
return false;
}
}
int ncircles = 20000;
float rx = -1, ry = -1;
ArrayList<Circle> circles = new ArrayList<Circle>(ncircles);
void setup() {
//size(1200, 600);
fullScreen();
initCircles();
}
void initCircles() {
circles.clear();
for(int i=0;i<ncircles;i++) {
Circle c = new Circle();
c.center = new PVector(random(width), random(height));
c.radius = random(60);
while(c.intersects(circles)) {
c.radius -= 0.5;
}
if(c.radius > 1) {
circles.add(c);
}
}
}
void mouseMoved() {
if(rx < 0) {
rx = mouseX;
ry = mouseY;
}
}
void draw() {
background(255);
noStroke();
fill(0);
for(Circle c : circles) {
ellipse(c.center.x - ((rx-mouseX) * (c.radius / 128)),
c.center.y - ((ry-mouseY) * (c.radius / 128)),
2 * c.radius,
2 * c.radius);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment