无法在数组类型 PShape[] 上调用 disableStyle()
Cannot invoke disableStyle() on the array type PShape[]
我的处理代码有问题。
我制作了一个网格 在随机位置填充了一些 SVG。使用 PNG 和 PImage 效果很好,但我想使用 SVG 来更改图标的描边颜色、粗细和大小。
在我将代码写入形状以使其与 SVG 一起工作后,我想放置一个 disableStyle() 来更改值,但我收到错误“无法在数组类型 PShape[] 上调用 disableStyle()” .
谁能告诉我问题出在哪里?
希望得到一些好的答案。谢谢!
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");
}
您的 Icon
变量是 PShape[]
类型。括号表示它是一个 array 个 PShape 对象。 Array
没有名为 disableStyle()
的方法,这就是为什么您会收到无法在 Icon
变量上调用该方法的错误。
要使用该方法,您需要访问数组中的各个 PShape 元素:
Icon[0].disableStyle(); // etc
我的处理代码有问题。 我制作了一个网格 在随机位置填充了一些 SVG。使用 PNG 和 PImage 效果很好,但我想使用 SVG 来更改图标的描边颜色、粗细和大小。
在我将代码写入形状以使其与 SVG 一起工作后,我想放置一个 disableStyle() 来更改值,但我收到错误“无法在数组类型 PShape[] 上调用 disableStyle()” .
谁能告诉我问题出在哪里?
希望得到一些好的答案。谢谢!
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");
}
您的 Icon
变量是 PShape[]
类型。括号表示它是一个 array 个 PShape 对象。 Array
没有名为 disableStyle()
的方法,这就是为什么您会收到无法在 Icon
变量上调用该方法的错误。
要使用该方法,您需要访问数组中的各个 PShape 元素:
Icon[0].disableStyle(); // etc