pointillism with no ball intersection
in
Programming Questions
•
2 years ago
Hi
I would like to draw balls randomly postitioned with different sizes and also that they take the color of the background image, like in the shiffman example of the pointillism sketch, exept the ellipses dont intersect with each other...
But there is a bug and i dont know how to fix it(float to array conversion).
thanks!
I would like to draw balls randomly postitioned with different sizes and also that they take the color of the background image, like in the shiffman example of the pointillism sketch, exept the ellipses dont intersect with each other...
But there is a bug and i dont know how to fix it(float to array conversion).
thanks!
- PImage img;
- boolean freeze = false;
- int maxCount = 5000;
- int currentCount = 1;
- float bright;
- float[] x = new float[maxCount]; //xPos
- float[] y = new float[maxCount]; //yPos
- float[] r = new float[maxCount]; //radius
- int[] closestIndex = new int[maxCount]; //index
- int minRadius = 3;
- int maxRadius = 50;
- boolean insection = true;
- float zusatzA = 1.5;
- void setup() {
- img = loadImage("domizai.jpg");
- size(img.width,img.height);//740,621
- background(img);
- smooth();
- // first circle
- /*x[0] = 200; y[0] = 100; r[0] = 50; closestIndex[0] = 0;*/
- }
- void draw() {
- background(img);
- ellipseMode(CENTER);
- // draw circle at random pos
- for (int j = 0; j < 40; j++) {
- int tx = (int)random(maxRadius, width-maxRadius); // look for random pos
- int ty = (int)random(maxRadius, height-maxRadius);
- int tr = minRadius;
- int loc = tx + ty*img.width;
- loadPixels();
- float r = red(img.pixels[loc]);
- float g = green(img.pixels[loc]);
- float b = blue(img.pixels[loc]);
- // find a pos with no intersection with others circles
- for(int i=0; i < currentCount; i++) {
- float d = dist(tx,ty, x[i],y[i]);
- if (d >= (tr + r[i])) insection = false; ////////////// there seems to be the problem
- else {
- insection = true;
- break; // nur ausserhlab des kreises
- }
- }
- if (freeze) insection = true;
- // no intection ... add a new circle
- if (insection == false) {
- // get closest neighbour and closest possible radius
- float tRadius = width;
- for(int i=0; i < currentCount; i++) {
- float d = dist(tx,ty, x[i],y[i]);
- if (tRadius > d-r[i]) {
- tRadius = d-r[i];
- closestIndex[currentCount] = i;
- }
- }
- if (tRadius > maxRadius) tRadius = maxRadius;
- // make more circles
- x[currentCount] = tx;
- y[currentCount] = ty;
- r[currentCount] = tRadius /zusatzA;
- currentCount++;
- }
- }
- // draw them
- for (int i=0 ; i < currentCount; i++) {
- noStroke();
- fill(255,0,0);
- ellipse(x[i],y[i], r[i]*2,r[i]*2);
- }
- if (currentCount >= maxCount) noLoop();
- }
1