//import processing.pdf.*; import megamu.physics.*; float DPI = 20;//47.9952;//72; float BIGGEST = 3.25; float SMALLEST = .75; float SPACING = 0.375; ParticleSystem world; Particle active; Vector3D center; float increaseBy = 2; boolean record = false; void setup(){ size( (int) ceil(17.5*DPI), (int) ceil(17.5*DPI) ); smooth(); center = new Vector3D( (float)width/2, (float)height/2, 0 ); world = new ParticleSystem(); world.addForce( new Collision(world, 1) ); world.addForce( new Drag(world, 0.2) ); world.addForce( new InCircle(world, center, 17*DPI) ); world.addForce( new CollideWithRing(world, center, 7.52*DPI, 0.75*DPI ) ); } void draw(){ /* if( record ){ beginRecord(PDF, "table-pattern-"+DPI+"dpi-"+millis()+".pdf"); }*/ background(255); world.tick(); if( active != null ){ if( increaseBy != 0 ){ if( active.size() > BIGGEST*DPI ) increaseBy = -2; if( active.size() < SMALLEST*DPI ) increaseBy = 2; active.setSize( active.size() + increaseBy ); } active.setPosition(mouseX, mouseY, 0); } Iterator particles = world.particleIterator(); while( particles.hasNext() ){ Particle p = (Particle) particles.next(); noStroke(); if(!record) fill(230); ellipse( p.position().x(), p.position().y(), p.size(), p.size() ); if(record){ strokeWeight(0); }else{ strokeWeight(1); } stroke(0); noFill(); ellipse( p.position().x(), p.position().y(), p.size() - SPACING*DPI, p.size() - SPACING*DPI ); } /* if( record ){ endRecord(); record = false; println("done"); } */ } void mousePressed(){ Iterator particles = world.particleIterator(); while( particles.hasNext() ){ Particle p = (Particle) particles.next(); if( containsPoint( p, mouseX, mouseY ) ){ active = p; increaseBy = 0; break; } } if( active == null ){ active = new Particle(SMALLEST*DPI, 1, new Vector3D(mouseX, mouseY, 0)); increaseBy = 3; world.addParticle(active); } } void mouseReleased(){ active = null; } void keyPressed(){ if(key==' '){ float pSize = random(0,1); pSize *= pSize; pSize = lerp(SMALLEST, BIGGEST, pSize); world.addParticle( new Particle(pSize*DPI, 1, new Vector3D(random(width), random(height), 0)) ); } if(keyCode==ENTER){ record = true; } if(key=='z'){ if( active != null ){ active.kill(); }else if( world.numberOfParticles() > 0 ){ Particle latest = world.getParticle( world.numberOfParticles()-1 ); latest.kill(); } } } boolean containsPoint( Particle p, float x, float y ){ if( abs(p.position().x() - x) > p.size()*0.5 ) return false; if( abs(p.position().y() - y) > p.size()*0.5 ) return false; float d = dist( p.position().x(), p.position().y(), x, y ); if( d > p.size()*0.5 ) return false; return true; }