当我向我的讲师询问关于一个小组项目的一段代码的建议时,我被带到了这个论坛。一般的想法是有两个图像在彼此的顶部,用户可以擦掉顶部的图像以显示下面的图像。
使用该论坛中的其他一些项目,我已经设法使基础知识运行起来,但是一旦用户放开鼠标,我就很难将代码放到起点。
我也将不胜感激有关如何将其转换为使用触摸屏的任何建议。我查看了处理应用程序中的多点触控代码,但是它不允许我向其中添加图像,如果我尝试使用计算机软件,它似乎不喜欢多点触控。有没有办法解决?
我目前拥有的代码如下,如果有任何建议或意见,我将不胜感激 - 提前致谢!
PImage img, front;
int xstart, ystart, xend, yend;
int ray;
void setup()
{
size(961, 534);
img = loadImage("back.jpg");
front = loadImage("front.jpg");
xstart = 0;
ystart = 0;
xend = img.width;
yend = img.height;
ray = 50;
}
void draw()
{
{
img.loadPixels();
front.loadPixels();
// loop over image pixels
for (int x = xstart; x < xend; x++)
{
for (int y = ystart; y < yend; y++ )
{
int loc = x + y*img.width;
float dd = dist(mouseX, mouseY, x, y);
// pixels distance less than ray
if (mousePressed && dd < 50)
{
// set equal pixel
front.pixels[loc] = img.pixels[loc];
}
else
{
if (!mousePressed)
{
// reset- this is what I have not been able to work as of yet
front.pixels[loc] = ;
}
}
}
}
img.updatePixels();
front.updatePixels();
// show front image
image(front, 0, 0);
}
}
慕盖茨4494581
相关分类