我一直在尝试使用Moore邻域创建蜂窝自动机,并在处理中取得了很大的成功。我设法使基本系统正常工作,现在我希望通过添加其他功能来试用它。现在,我检查细胞是否还活着。如果是的话,我可以使用fill()函数应用一种颜色,然后我可以根据单元格存活的时间来改变该颜色的饱和度。但是,我希望能够根据活细胞的位置(例如
此处显示图片:
从外观上看,虽然我不确定,但似乎使用了方程式来达到这种效果。这让我难过了约2天。我不想要答案,因为我想自己解决。但是,如果有人可以指出正确的方向,我将不胜感激!
现在,我已经使每个单元格成为Cell类的对象。我在其中存储单元的x,y坐标和当前的生存状态。它还包含一个draw()
方法:
根据细胞是否存活将不同的颜色应用于细胞(年龄变量存储该细胞存活时间的数字,以秒为单位)。
此:
是到目前为止的输出。就像我之前说过的,我希望它看起来像第一个链接中的示例图片。
答案 0 :(得分:3)
使用noise(x,y)
根据每个像元的坐标为每个像元计算Perlin噪声值。在绘制用于全局颜色渐变效果的单元格时,将此值映射为色调(或饱和度或亮度)。
更新:示例代码生成可更好地映射到整个色谱图的噪声(请参见before与after)。
{
final float resolution = 0.0175f;
noiseDetail(20);
colorMode(HSB, 1, 1, 1);
float[] hues = new float[width * height];
loadPixels();
float hueMax = 0;
float hueMin = 1;
for (int x = 0; x < width; x++) { // Create value hue per pixel.
for (int y = 0; y < height; y++) {
int i = (y * width) + x;
hues[i] = noise(x * resolution, y * resolution);
if (hues[i] > max) {
max = s[i];
} else {
if (hues[i] < min) {
min = hues[i];
}
}
}
}
for (int x = 0; x < width; x++) { // Maps hue value to a more complete spectrum; updates PApplet pixels[].
for (int y = 0; y < height; y++) {
int i = (y * width) + x;
float hue = map(hues[i], min/0.4f, max*0.9f, 0, 1); // constants found by experimenting
pixels[i] = color(hue, 1, 1); // only map hues in this example
}
}
updatePixels();
}