2015-11-25 55 views
-1

即時通訊試圖運行一個處理草圖,讓您從您的計算機中選擇一個圖像,當選擇在處理窗口中加載圖像,並且一旦點擊就會產生另外2張圖像,原始副本每個都有自己的效果當點擊,然後能夠保存這些圖像,到目前爲止,我可以打開圖像,並有一個副本與點化效果稍有變化,但我不能得到另一種效果的工作,我不知道如何保存它們,其他效果我本來計劃要像三角形,而不是橢圓形的彩畫立體派的影響,請幫助..試圖對處理中的圖像應用2種效果?

這裏是我的代碼....

Boolean imageAvailable = false; 
PImage picture = null; 

void setup() { 

    size(1280, 720); 
    selectInput("Select a file to process:", "fileSelected"); 

} 

void fileSelected(File selection) { 

    if (selection == null) { 
    println("Window was closed or the user hit cancel.");  
    } else { 
    picture = loadImage(selection.getAbsolutePath()); 
    imageAvailable = (picture != null); 

    } 
} 

void draw() { 
    if (imageAvailable) { 
    image(picture, 0, 0); 

    } 
} 

void mousePressed() { 

    if (imageAvailable) { 

    pointalise(picture, picture.width, 0); 

    }  
} 

void pointalise(PImage p, int sx, int sy) { 

    noStroke(); 

    final int POINTSIZE = 15; 

    for (int y = 0; y < p.height; y += random(POINTSIZE)) { 

    for (int x = 0; x < p.width; x += random(POINTSIZE)) { 
     color c = p.get(x, y); 
     fill(red(c), green(c), blue(c), random(255)); 
     float pSize = random(1, POINTSIZE);  
     ellipse(sx + x , sy + y, pSize, pSize);  
    } 
    } 

} 
+0

你的問題到底是什麼?第二個效應是什麼讓你感到困惑? –

回答

0

要能夠申請第二個過濾器,我會建議把兩個按鈕和兩個if語句。做一個按鈕類像這樣的(請不要隨便複製並粘貼):

class Button { 
int W, H; 
final static color BTNC = #00FFFF, TXTC = 0; 
final String label; 
final float x, y, xW, yH; 

Button(String name, int xx, int yy) { 

W = img.width; 
H = img.height; 

x = (float) xx; 
y = (float) yy; 

xW = (float) (xx + W); 
yH = (float) (yy + H); 

label = name; 

} 

void display() { 

fill(BTNC); 
rect(x, y, W, H); 
fill(TXTC); 
text(label, x, y); 
} 

boolean hasClicked() { 
return mouseX > x & mouseX < xW & mouseY > y & mouseY < yH && mousePressed == true; 
} 

} 

然後使這個類的兩個對象在主代碼,都放在裏面,如果你的平局語句()函數如果點擊它,則分配新的過濾器。

button1 
if (button1.hasClicked()){ 
picture.pointalise(......); 
} 
if (button2.hasClicked()){ 
picture.otherArtStyle(........); 
} 

原始照片將在濾波的圖片可以得出,因此阻止這種情況發生類似:

imageAvailable = false; 

每個語句中。