save, load and add more data to it... ?
in
Core Library Questions
•
2 years ago
Hi
I wanna load a txt file and write some more data to it. I would need to combine the vals[0] with x.[i]... (i guess).
But I am not sure how to to bring them together, so that if I save and start the sketch again, x[] or y[] are getting always bigger... Simplified, draw, save, load and continue to draw...
Right now, I am just able to load the drawing from the previous running... but not to add more to the file...
thanks!!!
I wanna load a txt file and write some more data to it. I would need to combine the vals[0] with x.[i]... (i guess).
But I am not sure how to to bring them together, so that if I save and start the sketch again, x[] or y[] are getting always bigger... Simplified, draw, save, load and continue to draw...
Right now, I am just able to load the drawing from the previous running... but not to add more to the file...
- int[] x = new int[0];
- int[] y = new int[0];
- String[] loadLines;
- float [] vals;
- void setup() {
- size(300, 300);
- }
- void draw() {
- background(204);
- stroke(0);
- noFill();
- beginShape();
- loadLines = loadStrings("lines.txt");
- for(int i = 0; i < loadLines.length; i++){
- vals = float(split(loadLines[i], "\t"));
- vertex(vals[0], vals[1]);
- }
- endShape();
- beginShape();
- for (int i = 0; i < x.length; i++) {
- vertex(x[i], y[i]);
- }
- endShape();
- if (x.length >= 1) {
- stroke(255);
- line(mouseX, mouseY, x[x.length-1], y[x.length-1]);
- }
- }
- void mousePressed() {
- x = append(x, mouseX);
- y = append(y, mouseY);
- }
- void keyPressed() {
- String[] lines = new String[x.length];
- for (int i = 0; i < x.length; i++) {
- lines[i] = x[i] +"\t" + y[i]; // "\t"
- }
- saveStrings("lines.txt", lines);
- exit(); // Stop the program
- }
thanks!!!
1