/**
Sparkler - The day 3 door for my 2010 Advent calendar
by Guru
*/
PImage img;
float pos;
boolean running = false;
void setup() {
size(300,300,P2D);
smooth();
img = makeTexture( 35 );
frameRate(25);
pos = height - 10;
textFont( loadFont( "Nice-48.vlw" ),24);
}
void draw() {
background(0);
stroke(50);
fill(50);
rect( width/2 -5, 0, 10, height - 10);
pos -= 0.3;
if (pos < 0) { running = false; }
if ( !running ) {
fill(255);
stroke(255);
text( "click to start", width/2-60, height/2 );
} else {
stroke(255);
for( int i =0; i < 36; i++) {
float r = random( width/2 );
line( width/2, pos, width/2 + cos( radians(i*10))*r, pos + sin(radians(i*10))*r);
}
blend(img, 0, 0, img.width, img.height, width/2 - img.width/2, int(pos) - img.width/2, img.width, img.height, ADD );
}
}
void mouseClicked() {
if (!running ) {
running = true;
pos = height - 10;
}
}
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;
}