0

私は2つのレイヤー(背面、前面)を持つSVGを持っています。
背面を色で塗りつぶす必要があります (色はランダムになります)。
でもフロントはそのままでいい。
前面に影響を与えずに背面を埋めるにはどうすればよいですか?

PShape elem;
PShape back;
PShape front;

void setup()
{
  size(900,600);
  background(255);
  fill(100);
  elem = loadShape("resources/images/elem.svg");
  back = elem.getChild("back");
  front = elem.getChild("front");
  smooth();
  noLoop();
}

void draw(){  
  elem.disableStyle();
  fill(0, 51, 102);
  noStroke();
  shape(back, 50, 50, 250, 250);
  shape(front, 50, 50, 250, 250);
}

ご協力ありがとうございました。

4

1 に答える 1

1

svgなしで正確な設定をテストするのは難しい. それでも、 pushStyle()と popStyle() のペアを使用して、図形の一部の描画スタイルを分離できるはずです。

例えば

PShape elem;
PShape back;
PShape front;

void setup()
{
  size(900,600);
  background(255);
  fill(100);
  elem = loadShape("resources/images/elem.svg");
  back = elem.getChild("back");
  front = elem.getChild("front");
  smooth();
  noLoop();
}

void draw(){  
  elem.disableStyle();
  pushStyle();
    fill(0, 51, 102);
    noStroke();
    shape(back, 50, 50, 250, 250);
  popStyle();
  pushStyle();
    shape(front, 50, 50, 250, 250);
  popStyle();
}

インデントは単なる視覚的な合図であり、実際には必要ありません。

于 2012-05-17T18:08:05.427 に答える