【发布时间】:2021-09-26 20:29:40
【问题描述】:
我一直在尝试让这个 java processing 程序工作,它看起来真的很简单,但由于某种原因,我不知道出了什么问题。我不习惯使用PVectors,所以我假设它与此有关。我将发布原件,然后我的非工作 p5.js 尝试。
我已经被困在这个问题上太久了。我实际上是在学习原始处理之前学习了 p5.js,所以也许这就是我犯了一个愚蠢的错误的原因。
目前,我得到的只是一个空白屏幕。此外,我在 linux 上运行,并且很难在 IDE 中找到一个具有实际可见和工作调试的 linux 版本,因此p5.js 模式通常可以正常工作。我只是通过在线托管来使用试错法。所以我不知道什么 IDE 会解释它给出的错误。
原创,在 Java IDE 中工作:
PImage img;
void setup(){
size(500, 500, P2D); //width and height should be similar to the picture's dimensions
img = loadImage("turner.jpg");
}
void draw(){
img.resize(500,500);
int len = img.pixels.length;
//print(len);
//print(img.width * img.height);
loadPixels();
for(int x = 0; x < img.width; x++){ // by row
for(int y = 0; y < img.height; y++) { // by column
int i = x + y * img.width; // i = index of grid columns
float n = warp(x, y, .003, 255);
int offset = (i-int(n)); //%len; // with a modulo the offset should wrap around
if (offset<0){
offset = 0;
}
color c = img.pixels[offset]; // --> ArrayIndexOutOfBoundsException
pixels[i] = color(c);
}
}
updatePixels();
}
float warp(int _x, int _y, float factor, int n_range) {
float n1 = noise((_x+0.0) * factor, (_y+0.0) * factor) * n_range;
float n2 = noise((_x+5.2) * factor, (_y+1.3) * factor) * n_range;
PVector q = new PVector(n1, n2);
float n3 = noise(((_x + q.x * 4) + 1.7) * factor, ((_y + q.y * 4) + 9.2) * factor) * n_range;
float n4 = noise(((_x + q.x * 4) + 8.3) * factor, ((_y + q.y * 4) + 2.8) * factor) * n_range;
PVector r = new PVector(n3, n4);
return noise((_x + r.x * 4) * factor, (_y + r.y * 4) * factor) * n_range;
}
【问题讨论】:
-
我认为您应该将标记从 Javascript 更改为 Java。
-
在线托管后,您可以使用检查元素来帮助调试。
标签: javascript processing p5.js