I've been working on porting some of my Processing code over to regular Java in NetBeans. So far so well, most everything works great, except for when I go to use non-grayscale colors.
I have a script that draws a spiral pattern, and should vary the colors in the spiral based on a modulus check. The script seems to hang, however, and I can't really explain why.
If anyone has some experience with Processing and Java, and you could tell me where my mistake is, I'd really love to know.
For the sake of peer-review, here's my little program:
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++;
}
}