gpt4 book ai didi

处理 如何根据草图中的位置改变颜色?

转载 作者:行者123 更新时间:2023-12-01 13:18:12 27 4
gpt4 key购买 nike

我一直在尝试使用 Moore 邻域在处理过程中创建元胞自动机,到目前为止非常成功。我已经设法使基本系统正常工作,现在我希望通过添加不同的功能来使用它。现在,我检查细胞是否存活。如果是,我使用 fill() 函数应用一种颜色,然后我可能会根据细胞存活的时间来改变该颜色的饱和度。但是,我希望能够根据它们的位置改变活细胞的颜色,例如

此处显示的图片:

enter image description here

从它的外观来看,似乎使用了一个方程式来实现这种效果,但我并不完全确定。这让我难住了大约 2 天了。我不想要答案,因为我想自己弄清楚。但是,如果有人能指出正确的方向,我将不胜感激!

现在,我已经让每个单元格成为 Cell 类的一个对象。我在那里存储了单元格的 x、y 坐标和当前的生存状态。它还包含一个 draw() 方法:

enter image description here

根据细胞是否存活(年龄变量存储细胞存活的时间,以秒为单位),它会为细胞应用不同的颜色。

这个:

enter image description here

是到目前为止输出的样子。就像我之前说过的,我想让它看起来像第一个链接中的示例图片。

最佳答案

使用 noise(x,y) 计算每个单元格的柏林噪声值,基于其坐标。在为全局颜色渐变效果绘制单元格时,将此值映射到色调(或饱和度或亮度)。


更新:生成更好地映射到整个色谱的噪声的示例代码(参见 beforeafter)。

{
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();
}

关于处理 如何根据草图中的位置改变颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52586418/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com