# P5 code into Java code

**URL:** <https://discourse.processing.org/t/p5-code-into-java-code/39141>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [October 7, 2022, 3:13pm UTC](https://discourse.processing.org/t/p5-code-into-java-code/39141 "2022-10-07T15:13:50Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hanna](https://avatars.discourse-cdn.com/v4/letter/h/b3f665/32.png) [@Hanna](https://discourse.processing.org/u/Hanna)\
**Post date:** [October 7, 2022, 3:13pm UTC](https://discourse.processing.org/t/p5-code-into-java-code/39141/1 "2022-10-07T15:13:50Z")

</div>

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

```auto
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)}

```

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [October 7, 2022, 3:25pm UTC](https://discourse.processing.org/t/p5-code-into-java-code/39141/2 "2022-10-07T15:25:27Z")

</div>

```auto
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);
        }
    }
}

```

---

<div class="post-metadata">

**Author:** ![Hanna](https://avatars.discourse-cdn.com/v4/letter/h/b3f665/32.png) [@Hanna](https://discourse.processing.org/u/Hanna)\
**Post date:** [October 7, 2022, 3:37pm UTC](https://discourse.processing.org/t/p5-code-into-java-code/39141/3 "2022-10-07T15:37:49Z")

</div>

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?

 ![Still a problem](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/1/f/1f4d83ca0f2854e81b8385c2b6ae70db517a08f7.png)

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [October 7, 2022, 3:46pm UTC](https://discourse.processing.org/t/p5-code-into-java-code/39141/4 "2022-10-07T15:46:15Z")

</div>

Corrected above

One ) too much

---

<div class="post-metadata">

**Author:** ![Hanna](https://avatars.discourse-cdn.com/v4/letter/h/b3f665/32.png) [@Hanna](https://discourse.processing.org/u/Hanna)\
**Post date:** [October 7, 2022, 3:54pm UTC](https://discourse.processing.org/t/p5-code-into-java-code/39141/5 "2022-10-07T15:54:30Z")

</div>

> [@Chrisir](#):
>
> `float TAU=TWO_PI;`

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

---

<div class="post-metadata">

**Author:** ![vkbr](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/vkbr/32/16844_2.png) [@vkbr](https://discourse.processing.org/u/vkbr)\
**Post date:** [October 7, 2022, 3:56pm UTC](https://discourse.processing.org/t/p5-code-into-java-code/39141/6 "2022-10-07T15:56:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [October 7, 2022, 3:58pm UTC](https://discourse.processing.org/t/p5-code-into-java-code/39141/7 "2022-10-07T15:58:57Z")

</div>

Eyes of an eagle…!

Well done.

---

<div class="post-metadata">

**Author:** ![Hanna](https://avatars.discourse-cdn.com/v4/letter/h/b3f665/32.png) [@Hanna](https://discourse.processing.org/u/Hanna)\
**Post date:** [October 7, 2022, 4:00pm UTC](https://discourse.processing.org/t/p5-code-into-java-code/39141/8 "2022-10-07T16:00:57Z")

</div>

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?

 ![Sand p5](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/1/e/1efa9fa2f460da500d128c085108616c699af079.png)

---

<div class="post-metadata">

**Author:** ![Hanna](https://avatars.discourse-cdn.com/v4/letter/h/b3f665/32.png) [@Hanna](https://discourse.processing.org/u/Hanna)\
**Post date:** [October 7, 2022, 4:18pm UTC](https://discourse.processing.org/t/p5-code-into-java-code/39141/9 "2022-10-07T16:18:37Z")

</div>

Do you have a Idea why that would not work?

---

<div class="post-metadata">

**Author:** ![Hanna](https://avatars.discourse-cdn.com/v4/letter/h/b3f665/32.png) [@Hanna](https://discourse.processing.org/u/Hanna)\
**Post date:** [October 7, 2022, 4:39pm UTC](https://discourse.processing.org/t/p5-code-into-java-code/39141/11 "2022-10-07T16:39:42Z")

</div>

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?)

---

<div class="post-metadata">

**Author:** ![vkbr](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/vkbr/32/16844_2.png) [@vkbr](https://discourse.processing.org/u/vkbr)\
**Post date:** [October 7, 2022, 4:48pm UTC](https://discourse.processing.org/t/p5-code-into-java-code/39141/12 "2022-10-07T16:48:54Z")

</div>

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 🙂
