2015-11-25 116 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; 

每个语句中。