/** * LBi Balls * By: Anthony Tripaldi */ int numBalls = 50; int range = 300; Ball[] balls = new Ball[numBalls]; void setup() { size(550,500,P3D); fill(255); noStroke(); sphereDetail(15); setBalls(); } void draw() { background(255); fill(255,0,0); lights(); //simple camera rotation translate( width/2, height/2, -400 ); rotate( radians(frameCount * 0.2) ); for( int i = 0; i < numBalls; i++ ) { balls[i].draw(); } } void mousePressed() { println( frameRate ); setBalls(); } void setBalls() { for( int i = 0; i < numBalls; i++ ) { balls[i] = new Ball(int(random(-range,range)), int(random(-range,range)), int(random(8,25))); } //sets a random connection to another ball guarenteeing //each ball having at least one line for( int i = 0; i < numBalls; i++ ) { balls[i].setConnection( balls[ int( random(numBalls) ) ] ); } } class Ball { float x, y; int sx, sy, size; int seed = int( random(10000) ); int count = 0; Ball connect; Ball( int Sx, int Sy, int Size ) { sx = Sx; sy = Sy; size = Size; //println( "sx: " + sx + " sy: " + sy ); } void setConnection( Ball ball ) { connect = ball; } void draw() { count++; x = sx + 25 * sin((seed + count)*.03); y = sy + 35 * cos((seed + count)*.03); pushMatrix(); translate( x, y ); sphere( size * (sin( (count+seed) * .02 ) + 2 ) ); stroke(180); line( 0, 0, 0, connect.x - x, connect.y - y, 0 ); noStroke(); popMatrix(); } }