我在开放式处理中得到了Gary George的万花筒代码。我尝试修改它以满足我的需求并将其导出到Web。但我在浏览器上渲染图像时遇到问题。它在桌面上运行良好,但在浏览器上运行不正常。我一直试图解决这个错误,但是......没有运气(但是,我希望)。
以下是代码:
/**
* Kaleidoscope by Gary George.
*
*Load an image.
*Move around the mouse to explore other parts of the image.
*Press the up and down arrows to add slices.
*Press s to save.
*
*I had wanted to do a Kaleidoscope and was inspired with the by Devon Eckstein's Hexagon Stitchery
*and his use of Mask. His sketch can be found at http://www.openprocessing.org/visuals/?visualID=1288
*/
PImage a;
int totalSlices=8; // the number of slices the image will start with... should be divisable by 4
int previousMouseX, previousMouseY; //store previous mouse coordinates
void setup()
{
size(500,500, JAVA2D);
background(0,0,0);
smooth(); //helps with gaps inbetween slices
fill(255);
frameRate(30);
a=loadImage("pattern.jpg");
}
void draw() {
if(totalSlices==0){
background(0,0,0);
image(a,0,0);
}
else{
if(mouseButton == LEFT){
background(0,0,0);
//the width and height parameters for the mask
int w =int(width/3.2);
int h = int(height/3.2);
//create a mask of a slice of the original image.
PGraphics selection_mask;
selection_mask = createGraphics(w, h, JAVA2D);
selection_mask.beginDraw();
selection_mask.smooth();
selection_mask.arc(0,0, 2*w, 2*h, 0, radians(360/totalSlices+.1)); //using 369 to reduce lines on arc edges
selection_mask.endDraw();
float wRatio = float(a.width-w)/float(width);
float hRatio = float(a.height-h)/float(height);
//println("ratio: "+hRatio+"x"+wRatio);
PImage slice = createImage(w, h, RGB);
slice = a.get(int((mouseX)*wRatio), int((mouseY)*hRatio), w, h);
slice.mask(selection_mask);
translate(width/2,height/2);
float scaleAmt =1.5;
scale(scaleAmt);
for(int k = 0; k<=totalSlices ;k++){
rotate(k*radians(360/(totalSlices/2)));
image(slice, 0, 0);
scale(-1.0, 1.0);
image(slice,0,0);
}
}
resetMatrix();
}
}
答案 0 :(得分:0)
您需要更改两件事以在JS模式下加载本地图像:
您的图片必须位于草图文件夹中名为data
的文件夹中。您可以自己制作文件夹并将图像放入其中。您仍然像以前一样加载图像,无需指定数据文件夹。
在JS模式下,您需要使用以下命令预加载图像:/* @pjs preload="pattern.jpg"; */
所以你的完整图片加载代码将是:
/* @pjs preload="pattern.jpg"; */
a = loadImage("pattern.jpg");