ArrayList particles; ArrayList clearParticle; int focusx, focusy; void setup(){ size( 500, 500 ); background( 0 ); focusx = (int)random( width ); focusy = (int)random( height ); particles = new ArrayList(); clearParticle = null; for( int i = 0; i < 10; i++ ){ color c = color( random( 50 ), random( 50 ), random( 100 ) ); particles.add( new Particle( focusx + 80 - random( 160 ), focusy + 80 - random( 160 ), 2-random(4), 2-random(4), c, 0 ) ); } } void loop(){ clearParticle = null; Iterator it = particles.iterator(); while( it.hasNext() ){ Particle p = ( Particle )it.next(); p.relax(); p.drawSelf(); } if( clearParticle != null ){ it = clearParticle.iterator(); while( it.hasNext() ){ Particle p = ( Particle )it.next(); particles.remove( p ); if( p.depth < 4 ){ for( int i = 0; i < 3; i++ ){ color c = color( random( 50 ), random( 50 ), random( 100 ) ); particles.add( new Particle( p.x, p.y, 2-random(4), 2-random(4), c, p.depth ) ); } } } } if( particles.size() == 0 ){ focusx = (int)random( width ); focusy = (int)random( height ); for( int i = 0; i < 10; i++ ){ color c = color( random( 50 ), random( 50 ), random( 100 ) ); particles.add( new Particle( focusx + 80 - random( 160 ), focusy + 80 - random( 160 ), 2-random(4), 2-random(4), c, 0 ) ); } } if( mousePressed ){ background( 0 ); } } class Particle{ float x, y; float lastx, lasty; float dx, dy; color c; int count; int depth; Particle( float x, float y, float dx, float dy, color c, int depth ){ this.x = x; this.y = y; this.lastx = x; this.lasty = y; this.dx = dx; this.dy = dy; this.c = c; this.count = 0; this.depth = depth+1; } void relax(){ dx += ( focusx - x ) * 0.01; dy += ( focusy - y ) * 0.01; x += dx; y += dy; //•ǂƂÌÕ“Ë”»’è if( x < 0 ){ x = 0; dx *= -1; } else if( x > width-1 ){ x = width-1; dx *= -1; } if( y < 0 ){ y = 0; dy *= -1; } else if( y > height-4 ){ y = height-4; dy *= -1; } c = subtract( c, color( 3, 3, 3 ) ); count++; if( count > 30 ){ if( clearParticle == null ){ clearParticle = new ArrayList(); } clearParticle.add( this ); } } void drawSelf(){ int addx, addy = 0; int pos; pos = width * (int)y + (int)x; pixels[pos] = add( pixels[pos], subtract( c, color( 40, 40, 40 ) ) ); pos = width * (int)y + (int)(x+1); pixels[pos] = add( pixels[pos], subtract( c, color( 20, 20, 20 ) ) ); pos = width * (int)y + (int)(x+2); pixels[pos] = add( pixels[pos], subtract( c, color( 40, 40, 40 ) ) ); pos = width * (int)(y+1) + (int)x; pixels[pos] = add( pixels[pos], subtract( c, color( 20, 20, 20 ) ) ); pos = width * (int)(y+1) + (int)(x+1); pixels[pos] = add( pixels[pos], c ); pos = width * (int)(y+1) + (int)(x+2); pixels[pos] = add( pixels[pos], subtract( c, color( 20, 20, 20 ) ) ); pos = width * (int)(y+2) + (int)x; pixels[pos] = add( pixels[pos], subtract( c, color( 40, 40, 40 ) ) ); pos = width * (int)(y+2) + (int)(x+1); pixels[pos] = add( pixels[pos], subtract( c, color( 20, 20, 20 ) ) ); pos = width * (int)(y+2) + (int)(x+2); pixels[pos] = add( pixels[pos], subtract( c, color( 40, 40, 40 ) ) ); lastx = x; lasty = y; } } color subtract( color c1, color c2 ){ float c1R = c1 >> 16 & 0xff; float c1G = c1 >> 8 & 0xff; float c1B = c1 & 0xff; float c2R = c2 >> 16 & 0xff; float c2G = c2 >> 8 & 0xff; float c2B = c2 & 0xff; color resultc = color( c1R-c2R, c1G-c2G, c1B-c2B ); return resultc; } color add( color c1, color c2 ){ float c1R = c1 >> 16 & 0xff; float c1G = c1 >> 8 & 0xff; float c1B = c1 & 0xff; float c2R = c2 >> 16 & 0xff; float c2G = c2 >> 8 & 0xff; float c2B = c2 & 0xff; color resultc = color( c1R+c2R, c1G+c2G, c1B+c2B ); return resultc; }