我正在尝试运行一个处理草图,让您从计算机中选择一个图像,当选择该图像时,将图像加载到处理窗口中,一旦点击就生成另外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;
}
}
然后在主代码中创建此类的两个对象,这两个对象都放在draw()函数中的if语句中,如果单击它则指定一个新的过滤器。
button1
if (button1.hasClicked()){
picture.pointalise(......);
}
if (button2.hasClicked()){
picture.otherArtStyle(........);
}
原始图片将被绘制在已过滤的图片上,因此要停止这种情况,请使用以下内容:
imageAvailable = false;
在每个陈述中。