yalaniv
November 26, 2021, 6:16pm
1
I have a loop which create graphics and save them into jpg files,
and save them as
saveFrame(“C:\process\test\colors-###.jpg”);
I create the graphics from randomize list of colors, and if the color red was chosen,
I want the file to be saved as colors-###-red .jpg
Is that possible?
Chrisir
November 26, 2021, 7:47pm
2
Hello,
yalaniv:
colors-###-red .jpg
what about colors-red-###.jpg ? Might be easier. (the other thing is also possible)
Than you only need an if-clause to distinguish I guess:
if(chosenColor==color(255,0,0)) {
saveFrame(“C:\process\test\colors-red-###.jpg”);
}
else {
saveFrame(“C:\process\test\colors-###.jpg”);
}
not tested
Warm regards,
Chrisir
2 Likes
yalaniv
November 28, 2021, 4:53pm
3
Thanks for your reply, but it won’t do the job I need, because it will change the order of the files,
but I got an idea for different problem I had, in different project, so… thanks
1 Like
Chrisir
November 29, 2021, 11:54am
4
You can sort by date
But you can of course make another way to enumerate the files
Instead of using the inbuilt automatically numeration
1 Like
yalaniv
November 29, 2021, 12:28pm
5
sort by date won’t help cause I need to upload them to a platform sort only by name
yalaniv
November 29, 2021, 12:29pm
6
However, if I am using my own variable,
Is there an option to use string as a file name?
Tested on macos
//global
int num = 0;
color chosenColor;
void setup() {
size(200,299);
}
void draw() {
}
void mouseClicked() {
//local
num++;
String dir = "path/to/dir/";
if(chosenColor==color(255,0,0)) {
saveFrame(dir + "colors-" + nf(num, 3) + "-red.jpg");
}
else {
saveFrame(dir + "colors-" + nf(num, 3) + ".jpg");
}
}
2 Likes