// fadetoy // -- experiments with transparency and fading // // Scott "Jerry" Lawrence // http://www.cis.rit.edu/~jerry/Software/p5 // // previous mouse positions int px = 0; int py = 0; boolean start = true; // first time through loop()? // set up our junk void setup() { size( 200, 200 ); noBackground(); // don't clear with each frame colorMode( RGB, 255, 255, 255, 255 ); // note the 4th '255' for transparency/alpha ellipseMode( CENTER_DIAMETER ); // draw ellipses from the center // clear the screen fill( 0, 0, 0, 255 ); rect( 0,0, width, height ); } // do some stuff void loop() { int x = mouseX; int y = mouseY; if( start ) // this eliminates the "ellipse from 0,0" bug { px = x; py = y; start = false; } // draw lines if the button is down, otherwise draw ellipses if( mousePressed ) { stroke( 0, 255, 255, 255 ); line( px, py, x, y ); } else { fill( 255, 0, 255, 100 ); ellipse( x, y, abs(px-x)+2, abs(py-y)+2 ); } // try a transparency fade noStroke(); int s = second(); if( (s&7) > 3 ) { // fade to white fill( 255,255,255, 10 ); // increase 10 to speed it up, decrease to slow down // due to integer transparency, (255,50,0,10) will leave lingering shadows } else { // fade to black fill( 0, 0, 0, 10 ); } rect( 0, 0, width, height ); // draw it // store our mouse positions for the next iteration px = x; py = y; // screengrab stuff /* if( keyPressed ) { if( key == 'G' ) screenGrab(); } */ }