-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathsafeFrame()
48 lines (41 loc) · 1.18 KB
/
safeFrame()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Be sure to give permission WRITE_EXTERNAL_STORAGE
import android.os.Environment;
String absolute_path = new String(Environment.getExternalStorageDirectory().getAbsolutePath());
int tel = 0, x;
boolean no_loop = true;
// Folowing file name is the folder you save your frames in.
// If it does not exist it will be created automatically
String frames_folder = "my_frames";
PImage pi;
void setup() {
size(100, 100);
}
void draw() {
if (no_loop) {
background(200);
if (x < 100) {
line(x, 0, x, 100);
x ++;
} else {
no_loop = false;
} // Saves each frame as frame-000001.png, frame-000002.png, etc.
saveFrames("frame-######.png"); // numbers(hashtags) will be included in saveFrame()
}
}
void saveFrames(String s) {
try {
File file = new File(absolute_path+"/"+frames_folder);
if (!file.exists()) {
boolean success = true;
success = file.mkdirs();
}
int maxHashes = 6;
tel++;
String fs = String.format("%1$" + maxHashes + "s", tel).replace(' ', '0');
pi = get(0, 0, width, height);
pi.save(file+"/"+fs+".png");
}
catch (Exception e) {
println("Error while saving frames: " + e);
}
}