mirror of
https://github.com/processing/processing4.git
synced 2026-01-30 03:41:15 +01:00
Re-adding Topics to SVN
This commit is contained in:
34
java/examples/Topics/File IO/SaveFile2/SaveFile2.pde
Normal file
34
java/examples/Topics/File IO/SaveFile2/SaveFile2.pde
Normal file
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* SaveFile 2
|
||||
*
|
||||
* This file a PrintWriter object to write data continuously to a file
|
||||
* while the mouse is pressed. When a key is pressed, the file closes
|
||||
* itself and the program is stopped. This example won't work in a web browser
|
||||
* because of Java security restrictions.
|
||||
*/
|
||||
|
||||
PrintWriter output;
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(200, 200);
|
||||
// Create a new file in the sketch directory
|
||||
output = createWriter("positions.txt");
|
||||
frameRate(12);
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
if (mousePressed) {
|
||||
point(mouseX, mouseY);
|
||||
// Write the coordinate to a file with a
|
||||
// "\t" (TAB character) between each entry
|
||||
output.println(mouseX + "\t" + mouseY);
|
||||
}
|
||||
}
|
||||
|
||||
void keyPressed() { // Press a key to save the data
|
||||
output.flush(); // Write the remaining data
|
||||
output.close(); // Finish the file
|
||||
exit(); // Stop the program
|
||||
}
|
||||
Reference in New Issue
Block a user