Saving images
The easiest way to share your work on the web is to upload images to Flickr or Facebook. You could take screenshots of your sketches and use those, but there are better ways to do this. Using the saveFrame()
function, you can save the contents of your Processing sketch to your hard drive.
How to do it...
We'll use a basic sketch to show how saving images works. The following code will generate 1000 transparent white circles on a black background.
void setup() { size( 640, 480 ); smooth(); } void draw() { background( 0 ); for ( int i = 0; i < 1000; i++ ) { fill( random( 255 ), 64 ); stroke( 255, 128 ); ellipse( random( width ), random( height ), 40, 40 ); } if ( keyPressed ) { saveFrame("images/artwork-####.png"); } }
The saved image will look somewhat like the following image:
How it works...
Within the draw()
function, we'll use the keyPressed
system variable. The value of this variable is true
if a key is pressed and false
if no keys are...