Search code examples
processing

Cannot invoke disableStyle() on the array type PShape[]


I got a problem with my processing Code. I made a grid witch is filled with some SVG's at an random position. With PNG's and the PImage it work's fine but I want to do it with SVG to change the Stroke Color, Weight and Size of the Icons.

After I wrote the Code into the Shape to get it work with SVG's I wanted to place an disableStyle() to change the values but I get the error "Cannot invoke disableStyle() on the array type PShape[]".

Anyone a suggestion what the Problem is?

Hope for some good answers. Thank you!

int countHorizontal = 12;
int countVertical = 6;
int seed = 0;

PShape[] Icon = new PShape[8];

void setup() {
  size(1600, 800);
  noLoop();
  randomSeed(seed);
  
  Icon[0] = loadShape("SVGIcons/Icon_1.svg"); Icon[1] = loadShape("SVGIcons/Icon_2.svg");
  Icon[2] = loadShape("SVGIcons/Icon_3.svg"); Icon[3] = loadShape("SVGIcons/Icon_4.svg");
  Icon[4] = loadShape("SVGIcons/Icon_5.svg"); Icon[5] = loadShape("SVGIcons/Icon_6.svg");
  Icon[6] = loadShape("SVGIcons/Icon_7.svg"); Icon[7] = loadShape("SVGIcons/Icon_8.svg");
}

void draw() {
  background(#eeeeee);
  
  Icon.disableStyle();
  
  strokeWeight(2);
  color(#000000);

  
  for (int i = 0; i < countHorizontal; i = i + 1) {
    for (int j = 0; j < countVertical; j = j + 1) {

      float w = float(width) / countHorizontal;
      float h = float(height) / countVertical;
      float x = w * i;
      float y = h * j;

      shape(Icon[(int)random(Icon.length)], x, y, 100, 100); 
    }
  }
}

void keyReleased() { 
  if (keyCode == LEFT) {
    seed = seed - 1;
  }

  if (keyCode == RIGHT) {
    seed = seed + 1;
  }
  
  randomSeed(seed);
  redraw();

  println(seed);

  //saveFrame("export/animation_####.png");
}

Solution

  • Your Icon variable is of type PShape[]. The brackets mean it is an array of PShape objects. Array does not have a method called disableStyle() which is why you get an error that you can’t invoke that method on the Icon variable.

    To use that method, you’ll need to access the individual PShape elements in the array:

    Icon[0].disableStyle(); // etc