Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // based upon
- // P_2_2_5_01.pde
- //
- // Generative Gestaltung, ISBN: 978-3-87439-759-9
- // First Edition, Hermann Schmidt, Mainz, 2009
- // Hartmut Bohnacker, Benedikt Gross, Julia Laub, Claudius Lazzeroni
- // Copyright 2009 Hartmut Bohnacker, Benedikt Gross, Julia Laub, Claudius Lazzeroni
- //
- // http://www.generative-gestaltung.de
- int maxCount = 5000; //max count of the cirlces
- int currentCount = 1;
- float[] x = new float[maxCount];
- float[] y = new float[maxCount];
- float[] r = new float[maxCount]; //radius
- float[] a1 = new float[maxCount]; //start angle
- float[] a2 = new float[maxCount]; //end angle
- int[] closestIndex = new int[maxCount]; //index
- float minRadius = 5;
- float maxRadius = 100;
- // for mouse and arrow up/down interaction
- float mouseRect = 30;
- void setup() {
- size(800, 800);
- noFill();
- smooth();
- cursor(CROSS);
- // first circle
- x[0] = 200;
- y[0] = 100;
- r[0] = 50;
- closestIndex[0] = 0;
- }
- void draw() {
- background(255);
- // create a random position
- float newX = random(0+maxRadius, width-maxRadius);
- float newY = random(0+maxRadius, height-maxRadius);
- float newR = minRadius;
- boolean intersection = false;
- // find out, if new circle intersects with one of the others
- for (int i=0; i < currentCount; i++) {
- float d = dist(newX, newY, x[i], y[i]);
- if (d < (newR + r[i])) {
- intersection = true;
- break;
- }
- }
- // no intersection ... add a new circle
- if (intersection == false) {
- // get closest neighbour and closest possible radius
- float newRadius = width;
- for (int i=0; i < currentCount; i++) {
- float d = dist(newX, newY, x[i], y[i]);
- if (newRadius > d-r[i]) {
- newRadius = d-r[i];
- closestIndex[currentCount] = i;
- }
- }
- if (newRadius > maxRadius) newRadius = maxRadius;
- x[currentCount] = newX;
- y[currentCount] = newY;
- r[currentCount] = newRadius;
- a1[currentCount] = random(0, TWO_PI) ;
- a2[currentCount] = random(PI/4, PI);
- currentCount++;
- }
- // draw them
- for (int i=0 ; i < currentCount; i++) {
- int f = (int) map(r[i], 5, 80, 20, 200);
- stroke(20);
- strokeWeight(1);
- ellipse(x[i], y[i], r[i]*2, r[i]*2);
- for (int j=1; j<4;j++) {
- arc(x[i], y[i], r[i]*j/2, r[i]*j/2, j*a1[i], j*a1[i]+a2[j]);
- }
- }
- if (currentCount >= maxCount) noLoop();
- }
- void keyReleased() {
- if (key == 's' || key == 'S') saveFrame(random(2323)+"_##.png");
- }
- void keyPressed() {
- // mouseRect ctrls arrowkeys up/down
- if (keyCode == UP) mouseRect += 4;
- if (keyCode == DOWN) mouseRect -= 4;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement