P5 code into Java code

Hello everyone,
I am getting into programming and processing and am finding it difficult to adapt code written for “p5” into “Java”. Can anyone possibly help me how to convert this code for sand into a java code?

Kind regards
Hanna

setup=_=>{createCanvas(W=1194,H=834)
stroke(255,210,100)
strokeWeight(f=2)}
draw=_=>{clear(t=map(sin(f+=0.01),-1,1,64,200))
for(y=0;y<H;y+=3)for(x=0;x<W;x+=3)
point(cos(r=noise(x/W,y/H-f)*t)*TAU+x,sin(r)*TAU+y)}
float f,t; 
int W,H;

void setup () {
    size(1111, 664); 

    W=width;
    H=height;

    stroke(255,210,100);
    strokeWeight(2);
}

void draw () {
    background (0); // not sure?

    t=map(sin(f+=0.01),-1,1,64,200);

    float TAU=TWO_PI;

    for(int y=0;y<H;y+=3){
        for(int x=0;x<W;x+=3){
            r=noise(x/W,y/H-f)*t;
            point(cos(r)*TAU+x,sin(r)*TAU+y);
        }
    }
}
3 Likes

Thank you very much Chrisir,
unfortunately I still have a little problem with it. Can you give me a hint why it doesn’t work?

1 Like

Corrected above

One ) too much

Do you see anything when you run the code?
I only get errors all the time

1 Like

float r =noise(x/W,y/H-f)*t; was missing float
I see things :eye: :eye:

2 Likes

Eyes of an eagle…!

Well done.

2 Likes

Thank you very much! Now I also see things… but somehow it doesn’t look like this example here :smiley:

Does anyone of you have an idea why not?

Do you have a Idea why that would not work?

Thank you very very much! I’ve been sitting here for so long trying to understand what’s happening…
This definitely helps me a lot!

It’s so cool that you can understand the code and even find bugs!

Thank you!

(Can I get in touch if I have any more questions?)

2 Likes

Sure can, this is a very friendly community here.:slight_smile: cheers

In Java you need to tell what you are going to assign to a var. if you divide a Float by an Int the result is going to be an int. So when ‘H’ and ‘W’ were ints all results have no decimals, ruining the noise making the pattern.
Have fun :slight_smile:

5 Likes