Save command in void?

Hi! I’m new to Processing and also to this forum.
I got some trouble with the void command; I couldn’t use a save(""); in a void. See an example below, when I execute it, it will say “ArrayIndexOutOfBoundsException: Coordinate out of bounds!”. How can I fix this, I want a file that Processing creates.
Thanks in advance :slight_smile:!


String Folder_Name="Test";
color[]Color=new color[10];
void setup(){
  Color[0]=color(0,0,0);
  File Folder1=new File(Folder_Name);
  Folder1.mkdir();
  CreateTexture(0);
}
void draw(){
}
void CreateTexture(int Number2){
  surface.setSize(500,500);
  background(Color[Number2]);
  save(Folder_Name+"\\A.PNG");
}
1 Like

to give you a start:

String outfile = "data/a.png";
color[]mycolor=new color[10];
boolean saveit = true;

void setup(){
  size(500,500);
  mycolor[0]=color(200,200,0);
}

void draw(){
  background(mycolor[0]);
  if ( saveit ) save(outfile); // the subdirectory is created automatically
  saveit = false; // do not save 60 files per sec.
}

1 Like

You can refer to the reference to learn about save() function. To find the sketch folder in the PDE click the menu Sketch >> Show Sketch Folder and it shall display your sketch folder.

To get the location of your current created folder in your OP, you can add the following line right after you create the folder: println(Folder1.getAbsolutePath());

Finally, Folder1 should be replace with folder1 aka notice the lower case letter. Capital letter is reserved for naming classes and variables should begin with lower case. This is not an issue of your code but more of best practices to ensure your code is readable by others.

Kf

2 Likes

Wow, thank you all! t worked for me, I think I understand it.

I figured out that surface.setSize created the problem of its failure. I removed that, and everything functioned perfectly. Thank you anyway!

1 Like