/**
Blowout candle - The day 12 door for my 2010 Advent calendar
by Guru
click on the candle ...
*/
PVector[] pos;
float[] ttl;
int COUNT = 200;
PImage img;
void setup() {
size(300,300,P2D);
pos = new PVector[COUNT];
ttl = new float[COUNT];
for( int i = 0; i < COUNT; i++) {
pos[i] = new PVector( width/2+ random(-5,5), height-i*60/COUNT-80 );
ttl[i] = random(100);
}
img = makeTexture( 35 );
}
boolean burn = true;
void draw() {
background(0);
noStroke();
for ( int i =0; i<40; i++) {
stroke( 60 + i*1.5, 0, 0 );
line( width/2-20 + i, height - 80, width/2-20 + i, height );
}
if (burn) {
blend(img, 0, 0, img.width, img.height, width/2 - img.width/2, height - 95 - img.height/2, img.width, img.height, ADD );
blend(img, 0, 0, img.width, img.height, width/2 - img.width/4 - int(random( -2, 2)), height - 105 - img.height/2, img.width/2, img.height, ADD );
} else {
strokeWeight(4);
stroke(32);
line( width/2, height - 80, width/2, height - 95 );
noStroke();
for( int i= 0; i < COUNT; i++) {
pos[i].add( new PVector( noise( frameCount/10, i/10 )-0.5, random( -1, 0)));
ttl[i] -= random( 0.1, 1);
if (ttl[i] > 0) {
float tmp = map( ttl[i], 0, 100, 0, 255);
fill( 64, tmp );
ellipse( pos[i].x, pos[i].y, (100 - ttl[i])/10, (100 - ttl[i])/10);
}
}
}
}
void mousePressed() {
burn = false;
}
PGraphics makeTexture( int r ) {
PGraphics res = createGraphics( r * 6, r * 6, P2D);
res.beginDraw();
res.loadPixels();
for ( int x = 0; x < res.width; x++) {
for( int y = 0; y < res.height; y++ ) {
float d = min( 512, 50* sq( r / sqrt( sq( x - 3 * r) + sq( y - 3 * r))));
//if ( d < 10 ) d = 0;
res.pixels[y * res.width + x] = color( min(255,d), min(255, d*0.8), d* 0.5 );
}
}
res.updatePixels();
res.endDraw();
return res;
}