int spacer = 20; // how much space do you want between circles // int circleWidth; // TBD by drawing space size int rowCirc=80; int colCirc=30; int cols = rowCirc; int rows = colCirc; Cell[][] grid; int leftBorder=50; int topBorder=6; float gridSpaceW; float gridSpaceH; float circleHeight; float circleWidth; float circleRad; float circleMin =.001; int iter1; boolean drawActive = false; void setup() { //noCursor(); size (1024,768); //frameRate(5); ellipseMode(CENTER); makeGrid(); grid = new Cell[cols][rows]; for (int i = 0; i < cols; i++) { for (int j = 0; j < rows; j++ ) { grid[i][j] = new Cell((i*gridSpaceW)+leftBorder+(gridSpaceW/2), (j*gridSpaceH)+topBorder+(gridSpaceH/2),circleRad,i + j); } } } float closestDist; void draw(){ background(0,0,0); fill(255,0,0,5); closestDist = width*height; // abritrarily high fill(#4422CC); for (int i = 0; i < cols; i++) { for (int j = 0; j < rows; j++ ) { grid[i][j].oscillate(); grid[i][j].display(); } } } void makeGrid() { gridSpaceW = ((width-(leftBorder*2))/rowCirc); gridSpaceH = ((height-(topBorder*2))/colCirc); // determine circle size from gridSpace circleWidth=gridSpaceW -(spacer); if (circleWidth <=0 ) { circleWidth =8; } circleHeight=gridSpaceH -(spacer); if (circleHeight <=0 ) { circleHeight =2; } // if gridSpace is so small that circles overlap -- make it bigger than circle if (gridSpaceW < circleWidth) { gridSpaceW = circleWidth + 4; } if (gridSpaceH < circleHeight) { gridSpaceH = circleHeight + 4; } println("gridSpaceW: " + gridSpaceW + " circleWidth: " + circleWidth); println("gridSpaceH: " + gridSpaceH + " circleHeight: " + circleHeight); if (circleWidth < circleHeight) { circleRad= circleWidth/2; } else { circleRad= circleHeight/2; } println("circleRad: " + circleRad); } class Cell { float x,y; float w,h; float angle; float rad; Integrator radii; Cell(float tempX, float tempY, float tempRad, float tempAngle) { x = tempX; y = tempY; /* w= tempW; h = tempH; */ rad = tempRad; // keep rad in case you don't want to use integrator angle = tempAngle; radii = new Integrator(rad, .9, 0.6); // damping, attraction } void oscillate() { angle += 0.2; } void display() { radii.update(); stroke(255, 0, 0, 15); smooth(); // calc color using sine wave // fill(127+127 * sin(angle)); fill (random(0,255),0,0,18); whatsNear(); ellipse(x,y,radii.value,radii.value); } void whatsNear() { if (drawActive == false) { iter1 = 1; drawActive = true; //println(" iter 1 setup"); } float d = dist(x, y, mouseX, mouseY); // if ((d < gridSpaceW*2) && (d < closestDist)) { //(d < radii.value + 5) if (d < width/30) { closestDist = d; if (closestDist < 1) {closestDist =1;} float factor = map(closestDist,0,width*.75,100,0); if (iter1 < 50) { radii.target((circleRad*iter1)*(factor/100)); println(iter1); iter1 = iter1 + 1; // println("closestdist: " + closestDist + " factor" + factor + " raduis " + radii.value + " circleRad: " + circleRad ); // fill(#FF4422); // red } else { drawActive = false; println("*************"); } } // if mouse is near else { radii.target(circleRad/4); } } // what's near } // circle class