用噪声填充矩形并在网格中复制
Fill rectangle with noise and duplicate in a grid
我正在尝试用充满白噪声的一个矩形的副本填充网格。
我可以用矩形创建网格,但不能用噪声填充它们。我可以制造白噪声,但不能用它填充网格。下面尝试创建原始。现在我想在例如 3x3 网格
中复制它
void setup(){
size(900,900);
background(0);
stroke(255);
noFill();
noiseDetail(5);
println(pixelWidth, pixelHeight);
}
void draw(){
background(0);
float scale = 0.01;
int w = 300;
int h = 300;
loadPixels();
for(int x = 0; x<w;x++){
for(int y = 0; y<h;y++){
float col = 255*noise(scale*x,scale*y,30*scale*frameCount);
pixels[x + y*900] = color(col);
}
}
updatePixels();
}
结果是一个充满噪点的 300x300 矩形。我希望其中 9 个在具有相同白噪声的网格中。
我建议编写一个函数,将噪声瓦片渲染到 PGraphics
对象:
PGraphics CreateTile(int w, int h, float scale)
{
PGraphics pg = createGraphics(w, h, JAVA2D);
pg.beginDraw();
for(int x = 0; x<w;x++){
for(int y = 0; y<h;y++){
float col = 255*noise(scale * x, scale * y, 30 * scale * frameCount);
pg.set(x, y, color(col));
}
}
pg.endDraw();
return pg;
}
然后您可以随意放置方块:
void draw(){
background(0);
int w = 300;
int h = 300;
PGraphics pg = CreateTile(w, h, 0.01);
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
image(pg, w*i, h*j);
}
}
}
我正在尝试用充满白噪声的一个矩形的副本填充网格。
我可以用矩形创建网格,但不能用噪声填充它们。我可以制造白噪声,但不能用它填充网格。下面尝试创建原始。现在我想在例如 3x3 网格
中复制它void setup(){
size(900,900);
background(0);
stroke(255);
noFill();
noiseDetail(5);
println(pixelWidth, pixelHeight);
}
void draw(){
background(0);
float scale = 0.01;
int w = 300;
int h = 300;
loadPixels();
for(int x = 0; x<w;x++){
for(int y = 0; y<h;y++){
float col = 255*noise(scale*x,scale*y,30*scale*frameCount);
pixels[x + y*900] = color(col);
}
}
updatePixels();
}
结果是一个充满噪点的 300x300 矩形。我希望其中 9 个在具有相同白噪声的网格中。
我建议编写一个函数,将噪声瓦片渲染到 PGraphics
对象:
PGraphics CreateTile(int w, int h, float scale)
{
PGraphics pg = createGraphics(w, h, JAVA2D);
pg.beginDraw();
for(int x = 0; x<w;x++){
for(int y = 0; y<h;y++){
float col = 255*noise(scale * x, scale * y, 30 * scale * frameCount);
pg.set(x, y, color(col));
}
}
pg.endDraw();
return pg;
}
然后您可以随意放置方块:
void draw(){
background(0);
int w = 300;
int h = 300;
PGraphics pg = CreateTile(w, h, 0.01);
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
image(pg, w*i, h*j);
}
}
}