标签:java colors processing spiral
我一直在努力将一些处理代码移植到NetBeans中的常规Java.到目前为止,除了当我使用非灰度颜色时,大多数一切都很好.
我有一个绘制螺旋图案的脚本,并应根据模数检查改变螺旋中的颜色.然而,该剧本似乎悬而未决,我无法解释原因.
如果有人对Processing和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;
}
希望这可以帮助.
标签:java,colors,processing,spiral 来源: https://codeday.me/bug/20190701/1345327.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。