2012-05-17 173 views
0

我有一個2層SVG(背面,正面)。
我需要用一種顏色填充背部(顏色將是隨機的)。
但前線必須保持原樣。
如何在不影響正面的情況下填充背部?處理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); 
} 

謝謝你的幫助。

回答

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(); 
} 

縮進只是一個視覺提示,並非實際需要。

+0

謝謝,它工作得很好! –