import traer.physics.*; import processing.opengl.*; Particle repel, attract; Particle[] particles; Attraction[] attractArray; Attraction[] repelArray; PVector[] position; int grid = 4; ParticleSystem physics; float velocitySample = 0; int amount; int index = 0; void setup() { size( 512, 512, P3D); frameRate( 60 ); amount = (( width * height ) / grid ) / grid; ellipseMode( CENTER ); background( 0x22222222 ); stroke(0x03FF6600); position = new PVector[ amount ]; physics = new ParticleSystem( 0, 0, 0, 0 ); physics.setIntegrator( ParticleSystem.MODIFIED_EULER ); particles = new Particle[ amount]; attractArray = new Attraction[amount]; repelArray = new Attraction[amount]; repel = physics.makeParticle( 5, width * 0.2, height * 0.5, 0 ); for( int i = 0; i < width; i += grid ) { for( int j = 0; j < height; j += grid) { particles[ index ] = physics.makeParticle( 1, i, j, 0); repelArray[ index ] = physics.makeAttraction(repel, particles[ index ], -4, 10); position[ index ] = new PVector( i, j ); index++; } } println( index ); } void draw() { fill( 0x04222222 ); rect( 0, 0, width, height ); repel.position().set( (float)mouseX, (float)mouseY, 0 ); index = 0; Particle p; for(int k = 0; k < amount; k++) { p = particles[ k ]; float posX = p.position().x(); float posY = p.position().y(); if( posX > width || posX < 0 || posY > height || posY < 0 ) { p.position().set( position[ k ].x, position[ k ].y, 0 ); p.velocity().set( 0, 0, 0 ); } point(particles[ k ].position().x(), particles[ k ].position().y()); } physics.tick(); }