/** random lightstreak by guru */ PImage img; PVector[] pos; int tox = 0; int toy = 0; int sox = 0; int soy = 0; int tx = 0; int ty = 0; int sx = 0; int sy = 0; void setup() { size(300,300,P2D); pos = new PVector[100]; img = makeTexture(4); tox = int( 50 + random( width- 100 )); toy = int( 50 + random( height- 100 )); sox = int( 50 + random( width- 100 )); soy = int( 50 + random( height- 100 )); tx = int( 50 + random( width- 100 )); ty = int( 50 + random( height- 100 )); sx = int( 50 + random( width- 100 )); sy = int( 50 + random( height - 100 )); } float f = 0; void draw() { background(0); float x = bezierPoint( tox, sox, sx, tx, f); float y = bezierPoint( toy, soy, sy, ty, f); f+=0.01; if ( f > 1 ) { f = 0; tox = tx; toy = ty; sox = int( tox + ( tx - sx ) * .5); soy = int( toy + ( ty - sy ) * .5); sx = int( 50 + random( width- 100 )); sy = int( 50 +random( height- 100 )); tx = int( 50 + random( width- 100 )); ty = int( 50 +random( height- 100 )); } for( int i = 0; i < 100; i++) { if (pos[i] != null) { blend( img, 0, 0, img.width, img.height, int(pos[i].x), int(pos[i].y), img.width, img.height, ADD ); } } for( int i = 0; i < 99; i++) { pos[i] = pos[i+1]; } pos[99] = new PVector( x,y ); } 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)))); res.pixels[y * res.width + x] = color( min(255,d), min(255, d*0.8), d* 0.5 ); } } res.updatePixels(); res.endDraw(); return res; }