How to save and load my program...

I have been working on this little program, where you can make rectangles around some pictures. Now I just need to save it, so when you open the program again the same pictures are marked.

Screenshot of the program: http://puu.sh/imm3Y/fcd4a25cc8.jpg

Have been trying to use the 'Save' button, to make a screenshot but it seems to make a screenshot everytime I click on a new picture.

Answers

  • you can load and save your program itself I guess...

    you probably have a grid telling what images are selected

    now store the grid on the hard drive using saveTable() or saveStrings()

    for the latter you could loop thru the1st line and place x for selected and o for not selected

    strLine[i] += 'x';

    then save

    ;-)

  • hmm, I new to this so havent used a grid.

    Example from the first picture:

    void draw() { image(Acerba,2,2); }

    void mousePressed() { if ((mouseButton == LEFT) && (mouseX > 2) && (mouseX < 34) && (mouseY > 2) && (mouseY < 34)) { stroke(255,0,0); strokeWeight(2); rect (2,2,32,32); } else if ((mouseButton == RIGHT) && (mouseX > 2) && (mouseX < 34) && (mouseY > 2) && (mouseY < 34)){ stroke(0,0,255); strokeWeight(2); rect (2,2,32,32); }

    Sry, if it's messy but maybe I should make it into a grid as you are saying?

  • edited June 2015

    ah, I thought you meant like start program - select 3 images - end the sketch - start again and the 3 images still are selected

    but you mean just store the mouse click in the first place

  • edited June 2015

    yeah grid...

    also you want to automize the positions

    and not have a if for each cell..... like in your example...

    if ((mouseButton == LEFT) && (mouseX > 2) && (mouseX < 34) && (mouseY > 2) && (mouseY < 34)) {
      stroke(255,0,0);
    
  • Oh, is it possible to save the mouse clicks or do I have to start over?

  • do you have one image or 20x3?

  • I have 66 images

  • edited June 2015 Answer ✓

    like this

    there are some advanced techniques involved like

    • a 2D grid (see tutorials on the web site) named grid (whixh holds all false at startup btw.

    • the ! means not, inverting the old value (like true becomes false...)

    • also double for-loop, one for the rows the other for the columns

    to do

    enter the mouseX mouseY if similar to what you got

    [EDITED]

    int cellSizeX = 16;
    int cellSizeY = 10;
    
    boolean [] [] grid = new boolean [400/cellSizeX] [400/cellSizeY];  // grid 
    
    void setup() { 
      size(600, 600); 
      background(255);
      stroke(255, 2, 2); 
      fill(0);
    } // func
    
    void draw() {
      background(255); 
      for (int x = 0; x < 400/cellSizeX; x++) { 
        for (int y = 0; y < 400/cellSizeY; y++) {
          if (grid[x][y])
            stroke(255, 2, 2);
          else 
            stroke(255, 2, 255);
          rect(x*cellSizeX+12, y*cellSizeY+19, 
          cellSizeX, cellSizeY);
        } // for
      } // for
    } // func
    
    void mousePressed() {
      for (int x = 0; x < 400/cellSizeX; x++) { 
        for (int y = 0; y < 400/cellSizeY; y++) {
          if (mouseX...............) {
            grid[x][y] = ! grid[x][y];
            return; // quit function 
          } // if
        } // for
      } // for
    } // func
    
    // 
    
  • Well, that looks advanced. I'll try to look into it.

    Thx, m8!

  • it's actually close to "most simple"

    think about it how powerful it is

    you can position the rects / images in one go and check mouse in one go.

    that's awesome - think: in your approach you typed numbers for the mouse; you'd had to type this line 33 times with different numbers and then again 33 lines with different numbers to draw the 33 images...

    man.....

    ;-)

  • edited June 2015

    400/cellSizeX

    just says "numbers of cells in a row"

    because the width of the grid is 400 and then we divide by the width of one cell to get the numbers of cells in a row

Sign In or Register to comment.