surface.setSize and a 2D array

Hi All

I am working on a surface.setSize with multiple sizes. Now i know how to do that. Inside the 'surface.setSize', i wanne use a 2dimensional array, but that doesnt work. I don't know why.

int cols = 400; int rows = 500;

int[][] size = new int[cols][rows];

void setup() { size(100, 100); surface.setResizable(true); }

void draw() { background(2); if (key == '1') { surface.setSize(size[][]) ; } else if (key == '2') { surface.setSize(size[][]) ; } }

Can anyone tell me the problem.

Tnanks@!

Answers

  • Not sure why you are using a 2D array. Try this next code.

    Kf

    void setup() { 
      size(100, 100); 
      surface.setResizable(true);
    }
    
    void draw() { 
      background(2); 
      if (key == '1') { 
        surface.setSize(200,200) ;
      } else if (key == '2') { 
        surface.setSize(500,500) ;
      }
    }
    
  • Thank you for your comment. I excually already knew how to do this. I was just wondering if i could make a 2D array of two values for inside a setSize

  • Answer ✓

    You variable size has 400 cols and 500 rows, for a total of 400*500 elements @-)

    Kf

  • edited January 2017

    @jaspervanblokland --

    You are saying "a 2D array" but do you actually mean an object that contains a pair of variables -- like a PVector can be used to express an x and a y?

    https://processing.org/reference/PVector.html

    PVector mysize;
    ...
    surface.setSize(mysize.x,mysize.y)
    

    ...and then you would want an array of PVectors (PVector[] mysizes) to contain multiple screen sizes...?

    PVector[] mysizes;
    ...
    surface.setSize(mysizes[i].x,mysizes[i].y)
    
  • Yes, that is what i meant! Thank you!

  • edited January 2017 Answer ✓
    PVector[] list = { 
      new PVector (111, 122), 
      new PVector (111, 142), 
      new PVector (154, 122)    
    };
    
    
    
    size (444, 777);
    
    // use a for loop here 
    ellipse (list[0].x, list[0].y, 5, 5);
    ellipse (list[1].x, list[1].y, 5, 5);
    ellipse (list[2].x, list[2].y, 5, 5);
    
    // or write a funtion that gets a PVector and a diameter as parameters
    
Sign In or Register to comment.