2014-01-06 149 views

回答

6

我不知道內置的方式,至少一般(你沒有提到你的代碼是如何組織的)。但是,這是一個DIY方法的快速演示。這個想法是,你在對象後面畫出一系列漸變和變暗的橢圓。你可能想根據自己的喜好來調整硬編碼的數字,也許它可以非線性地變得透明(可能更暗一些,也許會更暗)。

Thing thing1; 
Thing thing2; 

void setup(){ 
    size(300,300); 
    smooth(); 
    thing1 = new Thing(1*width/3,height/2,false); 
    thing2 = new Thing(2*width/3,height/2,true); 
} 
void draw(){ 
    background(100); 
    stroke(0); 
    line(100,100,250,250); 
    line(150,100,300,250); 
    thing1.display(); 
    thing2.display(); 
} 

class Thing 
{ 
    PVector loc; 
    boolean glowing; 
    Thing(int x, int y, boolean glow){ 
    loc = new PVector(x,y); 
    glowing = glow; 
    } 
    void display(){ 
    if(glowing){ 
     //float glowRadius = 100.0; 
     float glowRadius = 100.0 + 15 * sin(frameCount/(3*frameRate)*TWO_PI); 
     strokeWeight(2); 
     fill(255,0); 
     for(int i = 0; i < glowRadius; i++){ 
     stroke(255,255.0*(1-i/glowRadius)); 
     ellipse(loc.x,loc.y,i,i); 
     } 
    } 
    //irrelevant 
    stroke(0); 
    fill(0); 
    ellipseMode(CENTER); 
    ellipse(loc.x,loc.y,40,40); 
    stroke(0,255,0); 
    line(loc.x,loc.y+30,loc.x,loc.y-30); 
    line(loc.x+30,loc.y,loc.x-30,loc.y); 
    } 
} 

enter image description here

此外,如果你的對象不是圓形對稱的,你可以不喜歡以下。它會查看對象的像素,並在找到非空白像素的任何位置繪製幾乎透明的橢圓。儘管這是一個相當混亂的解決方案。遵循對象的邊緣或者其他方法可能會更好。我希望這給你一些想法!

Thing thing1; 

void setup(){ 
    size(300,300); 
    background(0); 
    thing1 = new Thing(); 
    thing1.display(); 
} 
void draw(){} 

class Thing 
{ 
    PGraphics pg; 
    Thing(){ 
    pg = createGraphics(200,200); 
    } 
    void display(){ 
    pg.beginDraw(); 
    pg.background(0,0); 
    pg.strokeWeight(10); 
    pg.stroke(255,100,0); 
    pg.line(100,50,100,150); 
    pg.line(75,50,125,50); 
    pg.line(75,150,125,150); 
    pg.line(30,100,170,100); 
    pg.endDraw(); 
    PGraphics glow = createGraphics(200,200); 
    glow.beginDraw(); 
    glow.image(pg,0,0); 
    glow.loadPixels(); 
    glow.fill(255,3); 
    glow.noStroke(); 
    //change the +=2 for different effects 
    for(int x = 0; x < glow.width; x+=2){ 
     for(int y = 0; y < glow.height; y+=2){ 
     if(alpha(glow.pixels[y*glow.width+x]) != 0) glow.ellipse(x,y,40,40); 
     } 
    } 

    glow.endDraw(); 
    //draw the glow: 
    image(glow,50,50); 
    //draw the sprite: 
    image(pg,50,50); 
    } 
} 

enter image description here

+0

題外話,但請不要提交小修改。除非你要糾正帖子中的其他問題,否則留給2k代表的人(或10k,如果這是一項重大任務)。 – bjb568

+0

@ bjb568謝謝你讓我知道。處理標籤沒有得到很多關注,所以常見的誤差並不總是得到糾正。不過,我從現在開始不管它。 – kevinsa5

+0

你可以在[meta](http://meta.stackoverflow.com)上提出來關注它。它可能需要被燒燬或大規模批發,這兩者你都做不到。 – bjb568

相關問題