加工中的各种颜色
我一直在努力将一些处理代码移植到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次迭代中使用非灰色。
我认为颜色值是这里的主要问题。从参考页面开始
从技术角度来看,颜色是按AAAAAAAARRRRRRRRGRGGGGGGGGBGBBBBBBBBBB排序的32位信息,其中A包含alpha值,R代表红色/色调值,G代表绿色/饱和度,B代表蓝色/亮度。
如果我们查看自己的值,将会看到一个非常低的alpha值,这可能无法与背景区分开。
感谢所有帮助,但我认为我的最终目标有些误解。
这是我使用处理PDE生成的图像:
http://www.deviantart.com/download/97026288/spiral_render_5_by_ishkur88.png
我想要的输出看起来类似于该输出,但螺旋的颜色和总体形状有所不同。
As the previous poster mentioned: you're using a non gray color only every 11th, 13th and 17th iteration.
感谢我们指出这一点,但我已经知道了!我实际上是这样设计的!
原因是这样,如果我没有灰色默认值,输出将是疯狂混乱的外观,并且非常不悦眼(至少我的眼睛)。
如果有一种方法可以让我完全跳过该圆圈的渲染,那么我当然会希望更多。
不知道我们是否还有问题。你提到挂。它是在黑暗中拍摄的,但是我记得炒到重复size()调用必须是setup()中的第一条指令。因此,向下移动background()调用可能会有所帮助。反正不会受伤。