Particle[] particles; void setup(){ background( 0 ); size( 200, 200 ); framerate(30); particles = new Particle[2]; for( int i = 0; i < particles.length; i++ ){ particles[i] = new Particle( random(width), random(height), random(2)+2, random(2)+2, random(0.9)+0.1, random(0.9)+0.1, random(0.9)+0.1 ); } } void loop(){ int i, x, y, pos; float xlen, ylen, len, a, fr, fg, fb; for( i = 0; i < particles.length; i++ ){ particles[i].relax(); } for( x = 0; x < width; x++ ){ for( y = 0; y < height; y++ ){ pos = y*width+x; fr = ( pixels[pos] >> 16 & 0xff ) -50; fg = ( pixels[pos] >> 8 & 0xff ) -50; fb = ( pixels[pos] & 0xff ) -50; for( i = 0; i < particles.length; i++ ){ xlen = x - particles[i].x; ylen = y - particles[i].y; len = ( float )Math.sqrt( xlen*xlen + ylen*ylen ); a = 2000/len; fr += a*particles[i].r; fg += a*particles[i].g; fb += a*particles[i].b; } pixels[pos] = ( (int)fr << 16 ) & ( (int)fg << 8 ) & (int)fb; } } } class Particle{ float x, y, dx, dy; float r, g, b; Particle( float x, float y, float dx, float dy, float r, float g, float b ){ this.x = x; this.y = y; this.dx = dx; this.dy = dy; this.r = r; this.g = g; this.b = b; } void relax(){ this.x += this.dx; this.y += this.dy; if( this.x < 0 || this.x >= width ){ this.dx *= -1; } if( this.y < 0 || this.y >= height ){ this.dy *= -1; } } }