/* * fancyBalls.pde */ int nBalls; int nSteps; float thresh; float vMax; //i, x,y,vx,vy float[][] balls; int ballShapeMode; int numBallShapes = 4; int movementMode; boolean applyThreshold; boolean renderDiscretely; boolean rorschach; boolean pause; boolean invertAlpha; boolean blackBackground; boolean smileyMode; color backgroundColor; color ballColor; boolean randomColor; PImage ballImage; int radius; void setup(){ frameRate(30); smooth(); noStroke(); resetParams(); //size(radius*10,radius*10); size(500,500); generateImage(); generateBalls(); } void resetParams(){ movementMode = 0; ballShapeMode = 0; applyThreshold = true; renderDiscretely = false; rorschach = true; pause = false; invertAlpha = false; blackBackground = false; smileyMode = true; randomColor = false; nBalls = 30; nSteps = 6; thresh = .1; vMax = 3; balls = new float[nBalls][4]; backgroundColor = color(255); ballColor = color(0); radius = 50; } void draw(){ if(!pause) moveBalls(); background(255); for(int i=0; i10){ radius = (int)(radius/1.2); println("radius: "+radius); generateImage(); } if(key == '=' && radius0){ thresh = thresh/1.2; println("threshold: "+thresh); } if(key ==']' && thresh*1.2<1){ thresh = thresh*1.2; println("threshold: "+thresh); } //change the number of steps in the discretized image if(key =='{' && nSteps>3){ nSteps--; generateImage(); println("nSteps: "+nSteps); } if(key =='}'){ nSteps++; generateImage(); println("nSteps: "+nSteps); } //add/remove balls if(key =='_'){ int newNBalls = nBalls; if(nBalls>0) newNBalls = (int)(nBalls/1.2); println("nBalls: "+nBalls+" to "+newNBalls); float[][] newBalls = new float[newNBalls][4]; for(int i =0; i= width) balls[i][2] = -balls[i][2]; if(balls[i][1]-radius <= 0 || balls[i][1]+radius >= height) balls[i][3] = -balls[i][3]; balls[i][2]+=random(-.1,.1); balls[i][3]+=random(-.1,.1); balls[i][2] = constrain(balls[i][2],-vMax,vMax); balls[i][3] = constrain(balls[i][3],-vMax,vMax); balls[i][0] +=balls[i][2]; balls[i][1] +=balls[i][3]; } } //a fountain! if(movementMode ==1){ float v = -(height+radius)/50; float theta = 0; for(int i=0; i width+radius || balls[i][1] > height+radius){ v += random(-2,2); theta = random(-.2,.2); balls[i][0] = width/2; balls[i][1] = height-radius; balls[i][2] = v*sin(theta); balls[i][3] = v*cos(theta); } balls[i][3]-= v/50; balls[i][0] +=balls[i][2]; balls[i][1] +=balls[i][3]; } } //swirling around if(movementMode ==2){ for(int i=0; i=radius && balls[i][0] <= width-radius && balls[i][1] >=radius && balls[i][1] <= height-radius){ balls[i][2]+= (width/2-balls[i][0])/(width/2)*random(.9,1.1); balls[i][3]+= (height/2-balls[i][1])/(height/2)*random(.9,1.1); balls[i][0]+= balls[i][2]; balls[i][1]+= balls[i][3]; } else{ balls[i][0] = random(radius,width-radius); balls[i][1] = random(radius,height-radius); balls[i][2] = 0; balls[i][3] = 0; } balls[i][0] +=balls[i][2]; balls[i][1] +=balls[i][3]; } } //orbits! if(movementMode ==3){ float rSquared = 0; float theta = 0; float vel0 = max(width,height)/150; float vel = vel0+0; for(int i=0; i max(width+radius,height+radius)*max(width+radius,height+radius)*.25){ println("escape"); balls[i][0] = random(radius,width-radius); balls[i][1] = random(radius,height-radius); balls[i][2] = 0; balls[i][3] = 0; } vel = vel0*(1-rSquared/(width*width/(3*3))); balls[i][0]+= vel*cos(theta+PI/2); balls[i][1]+= vel*sin(theta+PI/2); } } //swirl in! if(movementMode == 4){ float rSquared = 0; float theta = 0; float vel0 = max(width,height)/150; float vel = vel0+0; float rSquaredMax = (width/2+radius)*(width/2+radius); for(int i=0; i rSquaredMax || rSquared < 200.0){ rSquared = (width/2+radius/2)*(width/2+radius/2);//rSquaredMax*.9; theta = random(TWO_PI); balls[i][0] = width/2+sqrt(rSquared)*cos(theta); balls[i][1] = height/2+sqrt(rSquared)*sin(theta); balls[i][2] = 0; balls[i][3] = 0; } balls[i][0]-= (4*cos(theta+PI/2)+cos(theta)*(1+rSquared/rSquaredMax)); balls[i][1]-= (4*sin(theta+PI/2)+sin(theta)*(1+rSquared/rSquaredMax)); } } //They're all repulsive! if(movementMode == 5){ float rSquared = 0; float force = 0; float theta = 0; for(int i=0; i