# Convert processing to p5js code

**URL:** <https://discourse.processing.org/t/convert-processing-to-p5js-code/27405>\
**Category:** Coding Questions\
**Created:** [January 27, 2021, 9:14am UTC](https://discourse.processing.org/t/convert-processing-to-p5js-code/27405 "2021-01-27T09:14:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![l3ehfar](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/l3ehfar/32/4074_2.png) [@l3ehfar](https://discourse.processing.org/u/l3ehfar)\
**Post date:** [January 27, 2021, 9:14am UTC](https://discourse.processing.org/t/convert-processing-to-p5js-code/27405/1 "2021-01-27T09:14:55Z")

</div>

I need some help converting this Processing sketch to P5js sketch. I would be glad if someone helped me.

```auto
float unit, theta;
int num = 25, frames=180;

void setup() {
  size(500, 500);
  unit = width/num;
}

void draw() {
  fill(0,30);
  noStroke();
  rect(0,0,width, height);
  fill(255);
  for (int y=0; y<=num; y++) {
    for (int x=0; x<=num; x++) {
      float distance = dist(width/2, height/2, x*unit, y*unit);
      float offSet = map(distance, 0, sqrt(sq(width/2)+sq(height/2)), 0, TWO_PI);
      float sz = map(sin(theta+offSet), -1, 1, unit*.2, unit*.1);
      float angle = atan2(y*unit-height/2, x*unit-width/2);
      pushMatrix();
      translate(x*unit, y*unit);
      rotate(angle);
      float px = map(sin(theta+offSet),-1,1,0,50);
      ellipse(px,0, sz, sz);
      popMatrix();
    }
  }
  stroke(255);

  theta -= TWO_PI/frames;
}

```

this is what I’ve converted but have no idea why doesn’t it work well. [p5.js Web Editor](https://editor.p5js.org/l3ehfar/sketches/dGY5SA2n2)

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [January 27, 2021, 10:16am UTC](https://discourse.processing.org/t/convert-processing-to-p5js-code/27405/2 "2021-01-27T10:16:46Z")

</div>

`let unit, theta;` - - - \> `let unit, theta = 0;`
