/**
Pointlight candle - The day 4 door for my 2010 Advent calendar
by Guru
*/
PImage img;
void setup() {
size(300,300, P3D);
img = makeTexture( 15 );
}
void draw() {
background(0);
pointLight( 255,255,255,mouseX,mouseY, 100);
pushMatrix();
translate( width/2, height/2 );
stroke(255,0,0);
noStroke();
fill(255,0,0);
sphere( 50 );
translate( 0, -50, 0 );
fill( 200, 128, 0 );
sphere( 10 );
translate( 0, -75, 0 );
fill( 128 );
box( 1, 150, 1 );
popMatrix();
for( int i =0; i < 10; i++) {
stroke( 64 + i * 4,0, 0);
line( mouseX - 5 + i, mouseY, mouseX -5 + i, mouseY -25 );
}
blend( img, 0,0, img.width, img.height, mouseX - img.width/2, mouseY - img.width/2 -30, img.width, img.height, ADD );
blend( img, 0,0, img.width, img.height, mouseX - img.width/4 + int(random(-2,2)), mouseY - img.width/2 - 36, img.width/2, img.height, ADD );
}
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;
}