处理中变化的颜色
我一直在努力将一些处理代码移植到NetBeans中的常规Java。到目前为止,大多数情况都很好,除了当我使用非灰度色彩时。处理中变化的颜色
我有一个脚本,绘制螺旋模式,并应根据模数检查改变螺旋的颜色。脚本似乎挂起,但是,我不能解释为什么。
如果任何人有处理和Java的一些经验,你可以告诉我我的错误在哪里,我真的很想知道。
对于同行评议的缘故,这里是我的小程序:
package spirals;
import processing.core.*;
public class Main extends PApplet
{
float x, y;
int i = 1, dia = 1;
float angle = 0.0f, orbit = 0f;
float speed = 0.05f;
//color palette
int gray = 0x0444444;
int blue = 0x07cb5f7;
int pink = 0x0f77cb5;
int green = 0x0b5f77c;
public Main(){}
public static void main(String[] args)
{
PApplet.main(new String[] { "spirals.Main" });
}
public void setup()
{
background(gray);
size(400, 400);
noStroke();
smooth();
}
public void draw()
{
if(i % 11 == 0)
fill(green);
else if(i % 13 == 0)
fill(blue);
else if(i % 17 == 0)
fill(pink);
else
fill(gray);
orbit += 0.1f; //ever so slightly increase the orbit
angle += speed % (width * height);
float sinval = sin(angle);
float cosval = cos(angle);
//calculate the (x, y) to produce an orbit
x = (width/2) + (cosval * orbit);
y = (height/2) + (sinval * orbit);
dia %= 11; //keep the diameter within bounds.
ellipse(x, y, dia, dia);
dia++;
i++;
}
}
你有没有考虑加入调试语句(的System.out.println)来看,在Java控制台?
可能会有大量的输出和明确的减速,但至少可以看到什么情况发生时什么都不会发生。
我认为是逻辑错误是填充if语句;每次迭代都会决定该迭代的颜色并填充该颜色。只有i == 11,13或17的迭代才会被填充颜色。然后下一次迭代该颜色被灰色覆盖。我认为它往往闪烁,可能很快看到。
没有你想要的东西像
public class Main extends PApplet
{
...
int currentColor = gray;
public Main(){}
...
public void draw()
{
if(i % 11 == 0)
currentColor = green;
else if(i % 13 == 0)
currentColor = blue;
else if(i % 17 == 0)
currentColor = pink;
else {
// Use current color
}
fill(currentColor);
...
}
在你开始与灰色的那个样子,去绿色,蓝色,粉色,绿色,蓝色,粉红色等,如果你 也希望看到在灰色有些观点你必须添加一些像
else if (i % 19) {
currentColor = gray;
}
希望这会有所帮助。
要看到最新发生在这里添加
stroke(255);
在抽签开始。你会看到所有想要画的圈子,但没有颜色。正如前面的海报所提到的那样:您只在每次11,13和17次迭代时使用非灰色。
我认为你的颜色值是这里的主要问题。如从参考页
从技术角度来看,颜色的排序为AAAAAAAARRRRRRRRGGGGGGGGBBBBBBBB其中A的含有α值32位信息,将R的是红色/色调值,G的是绿色/饱和度,和B的是蓝/亮度。
如果你看看你的值,你会看到一个非常低的alpha值,这可能无法区分背景。
感谢所有的帮助,但我认为我的最终目标有点被误解。
这是我生成使用上述处理PDE图像:
http://www.deviantart.com/download/97026288/spiral_render_5_by_ishkur88.png
我的期望输出趋于看起来相似,在着色和螺旋的总体形状不同。
正如前面提到的海报:你只使用非灰色,每11,13和17次迭代。
感谢您指出这一点,但我已经知道了!我其实是这样设计的!
原因是,如果我没有灰色的默认值,输出将会疯狂地看起来非常混乱,而且对眼睛来说非常不愉快(至少我的眼睛)。
如果有一种方法可以完全跳过渲染那个圆,我一定会更喜欢这个。
不知道你是否还有问题。你提到悬挂。这是在黑暗中拍摄的,但我记得重复这个size()调用必须是setup()中的第一条指令。所以也许顺着background()调用可能会有所帮助。无论如何不能伤害。