Circle Packing 003

Rupert Russell

Ballarat, Australia

  • Available
    Products
    53
  • Artist
    Notes
  • Artwork Comments 2

Apparel

Cases & Skins

Wall Art

Home Decor

Accessories

Stationery

Artist's Description

// From https://www.openprocessing.org/sketch/176094
// Circle No Intersect NEW" by Michael Pinn
//http://www.openprocessing.org/sketch/176094

ArrayList<Circle> circles = new ArrayList<Circle>();

float num = 5000; // size of circle to fill
int click;
int min = 2;
int max = 500;
int count = 0;
int oldCount = 0;
int currentCount = 0;

/* Our object */
Circle c = new Circle(new PVector(0, 0), (int)random(min, max));

void setup() {
size(12000, 12000);
noStroke();
circles.add©;
}

void draw() {
background(255);
for(int i = 0; i < circles.size(); i++){
Circle c = (Circle) circles.get(i);
c.draw();
currentCount ++;

if(currentCount == oldCount + 5000000){
save(“circle005-” + currentCount / 5000000 + “.png”);
oldCount = currentCount;
}

}

PVector newLoc = new PVector(random(width/2-num, width/2+num), random(height/2-num, height/2+num));
int newD = (int) random(min, max);
while (detectAnyCollision (circles, newLoc, newD)) {
/* If the values do interect make new values. */
newLoc = new PVector(random(width/2-num, width/2+num), random(height/2-num, height/2+num));
newD = (int) random(min, max);
}

c = new Circle(newLoc, newD);
if(circles.size() < 1000000000 ){
circles.add©;
}
}

static boolean detectAnyCollision(ArrayList<Circle> circles, PVector newLoc, int newR) {
for (Circle c : circles) {
if (c.detectCollision(newLoc, newR)) {
return true;
}
}
return false;
}

class Circle {
PVector loc;
int d;

Circle(PVector loc, int d) {
this.loc = loc;
this.d = d;
}

void draw() {
float r = dist(loc.x, loc.y, width/2, height/2);
float c = abs(cos(radians®));
float s = abs(sin(radians®));
fill((c-s)255, c255, s*255);
if (r < num) {
ellipse(loc.x, loc.y, d, d);
}
}

boolean detectCollision(PVector newLoc, int newD) {
/*
We must divide d + newD because they are both diameters. We want to find what both radius’s values are added on.
However without it gives the balls a cool forcefeild type gap.
*/
return dist(loc.x, loc.y, newLoc.x, newLoc.y) < ((d + newD)/2);
}
}

void keyTyped() {
println("typed " + int(key) + " " + keyCode);
if (int(key) == 115) { // s
frame.setLocation(displayWidth/2-width/2, displayHeight/2-height/2);
println(“center dam it!”);
save(“circle005a-” + click + “.png”);
println("Saved: " + “circle005-” + click + “.png”);
click ++;
}

if (int(key) == 120) {
println(“Exit Program”);
exit(); // x to exit the program
}
}

// Save when mouse is clicked
void mouseClicked() {

save(“circle005a-” + click + “.png”);
println("Saved: " + “circle005a-” + click + “.png”);
click ++;
// exit();
// noLoop();
}

Artwork Comments

desktop tablet-landscape content-width tablet-portrait workstream-4-across phone-landscape phone-portrait
desktop tablet-landscape content-width tablet-portrait workstream-4-across phone-landscape phone-portrait