Hanna
October 7, 2022, 3:13pm
1
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
Hanna
October 7, 2022, 3:37pm
3
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
Hanna
October 7, 2022, 3:54pm
5
Chrisir:
float TAU=TWO_PI;
Do you see anything when you run the code?
I only get errors all the time
1 Like
vkbr
October 7, 2022, 3:56pm
6
float r =noise(x/W,y/H-f)*t;
was missing float
I see things
2 Likes
Hanna
October 7, 2022, 4:00pm
8
Thank you very much! Now I also see things… but somehow it doesn’t look like this example here
Does anyone of you have an idea why not?
Hanna
October 7, 2022, 4:18pm
9
Do you have a Idea why that would not work?
Hanna
October 7, 2022, 4:39pm
11
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
vkbr
October 7, 2022, 4:48pm
12
Sure can, this is a very friendly community here. 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
5 Likes