Advertisement
xeromino

arcs

Feb 22nd, 2014
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.60 KB | None | 0 0
  1. // based upon
  2. // P_2_2_5_01.pde
  3. //
  4. // Generative Gestaltung, ISBN: 978-3-87439-759-9
  5. // First Edition, Hermann Schmidt, Mainz, 2009
  6. // Hartmut Bohnacker, Benedikt Gross, Julia Laub, Claudius Lazzeroni
  7. // Copyright 2009 Hartmut Bohnacker, Benedikt Gross, Julia Laub, Claudius Lazzeroni
  8. //
  9. // http://www.generative-gestaltung.de
  10.  
  11. int maxCount = 5000; //max count of the cirlces
  12. int currentCount = 1;
  13. float[] x = new float[maxCount];
  14. float[] y = new float[maxCount];
  15. float[] r = new float[maxCount]; //radius
  16. float[] a1 = new float[maxCount]; //start angle
  17. float[] a2 = new float[maxCount]; //end angle
  18. int[] closestIndex = new int[maxCount]; //index
  19.  
  20. float minRadius = 5;
  21. float maxRadius = 100;
  22.  
  23. // for mouse and arrow up/down interaction
  24. float mouseRect = 30;
  25.  
  26. void setup() {
  27.   size(800, 800);
  28.   noFill();
  29.   smooth();
  30.   cursor(CROSS);
  31.  
  32.   // first circle
  33.   x[0] = 200;
  34.   y[0] = 100;
  35.   r[0] = 50;
  36.   closestIndex[0] = 0;
  37. }
  38.  
  39.  
  40.  
  41. void draw() {
  42.   background(255);
  43.  
  44.   // create a random position
  45.   float newX = random(0+maxRadius, width-maxRadius);
  46.   float newY = random(0+maxRadius, height-maxRadius);
  47.   float newR = minRadius;
  48.  
  49.   boolean intersection = false;
  50.  
  51.   // find out, if new circle intersects with one of the others
  52.   for (int i=0; i < currentCount; i++) {
  53.     float d = dist(newX, newY, x[i], y[i]);
  54.     if (d < (newR + r[i])) {
  55.       intersection = true;
  56.       break;
  57.     }
  58.   }
  59.  
  60.   // no intersection ... add a new circle
  61.   if (intersection == false) {
  62.     // get closest neighbour and closest possible radius
  63.     float newRadius = width;
  64.     for (int i=0; i < currentCount; i++) {
  65.       float d = dist(newX, newY, x[i], y[i]);
  66.       if (newRadius > d-r[i]) {
  67.         newRadius = d-r[i];
  68.         closestIndex[currentCount] = i;
  69.       }
  70.     }
  71.  
  72.     if (newRadius > maxRadius) newRadius = maxRadius;
  73.  
  74.     x[currentCount] = newX;
  75.     y[currentCount] = newY;
  76.     r[currentCount] = newRadius;
  77.     a1[currentCount]  = random(0, TWO_PI) ;
  78.     a2[currentCount]  = random(PI/4, PI);
  79.     currentCount++;
  80.   }
  81.  
  82.   // draw them
  83.   for (int i=0 ; i < currentCount; i++) {
  84.     int f = (int) map(r[i], 5, 80, 20, 200);
  85.     stroke(20);
  86.     strokeWeight(1);
  87.     ellipse(x[i], y[i], r[i]*2, r[i]*2);
  88.     for (int j=1; j<4;j++) {
  89.       arc(x[i], y[i], r[i]*j/2, r[i]*j/2, j*a1[i], j*a1[i]+a2[j]);
  90.     }
  91.   }
  92.  
  93.   if (currentCount >= maxCount) noLoop();
  94. }
  95.  
  96. void keyReleased() {
  97.   if (key == 's' || key == 'S') saveFrame(random(2323)+"_##.png");
  98. }
  99.  
  100. void keyPressed() {
  101.   // mouseRect ctrls arrowkeys up/down
  102.   if (keyCode == UP) mouseRect += 4;
  103.   if (keyCode == DOWN) mouseRect -= 4;
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement