6dc0e9a07bcff97ac9b111f36e12f1f6

I'm trying to move out of Processing's PDE and into a more standard IDE (NetBeans). So far everything has gone fairly well. Importing the core.jar is about all it takes to get going with Processing in a normal Java environment. My issue lies with a if...else in my draw() method.

What my script does is plot an ellipse along an increasing orbit. Depending on what you set as the orbit gain, the speed, and if you have acceleration, it can turn out at somewhat interesting.

I tried to add coloration to the script.
if( diameter == 5 ) fill( green );
if( diameter == 10) fill( pink );
etc.

In the PDE this type of thing works fine, but for some reason regular old Java doesnt like this. I don't get any errors, I just dont get anything at all. If I could see how the PDE interprets what I put in there, then I might be able to figure out what I'm doing wrong... but until I can figure that out, does anyone have any ideas?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package spirals;
import processing.core.*;

public class Main extends PApplet
{
    float x;
    float y;
    int i = 1;
    int dia = 1;
    
    float angle = 0.0f;
    float speed = 0.05f;
    float orbit = 0f;
    
    //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 );
        fill( gray );
        stroke( gray );
        strokeWeight( 4 );
        smooth();
    }
    
    public void draw()
    {   
        //take the mod of i and decide what to
        //set as the fill color
        if( i % 11 == 0 )
            fill( green );
        else if( i % 13 == 0 )
            fill( blue );
        else if( i % 15 == 0 )
            fill( pink );
        else if( i % 17 == 0 )
            fill( gray );
        
        orbit += 0.1f; //ever so slightly increase the orbit
        //speed += 0.00001f; acceleration
        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++;
    }
}

Refactorings

No refactoring yet !

81a73740df646bc6cccbfef6fab61ec9

Simon Hartley

October 25, 2008, October 25, 2008 13:12, permalink

No rating. Login to rate!

I think the reason that this doesn't do anything is because your main method hasn't asked it to do anything. It's referring to PApplet.main, which has no relation at all to you Main class. You asked it to show a default PApplet and that's what it has done, unless I'm misunderstanding and somehow the String you're passing to the main method is supposed to take a path name of a class to find, rather than just being some type of label.

81a73740df646bc6cccbfef6fab61ec9

Simon Hartley

October 25, 2008, October 25, 2008 13:25, permalink

No rating. Login to rate!

I take back what I said. I managed to get this working by replacing the constructor with:
public Main(){ super(); init();}

Your refactoring





Format Copy from initial code

or Cancel