# Translation from Processing to p5 not working

**URL:** <https://discourse.processing.org/t/translation-from-processing-to-p5-not-working/13051>\
**Category:** Coding Questions\
**Created:** [July 29, 2019, 7:05pm UTC](https://discourse.processing.org/t/translation-from-processing-to-p5-not-working/13051 "2019-07-29T19:05:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![SheCurvesMobius](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/shecurvesmobius/32/7054_2.png) [@SheCurvesMobius](https://discourse.processing.org/u/SheCurvesMobius)\
**Post date:** [July 29, 2019, 7:05pm UTC](https://discourse.processing.org/t/translation-from-processing-to-p5-not-working/13051/1 "2019-07-29T19:05:51Z")

</div>

Hi all, I can’t figure out why this isn’t spinning. Any tips? (It works in Processing).

```auto
var spin;

function setup() {
  createCanvas(400, 400);
  background(255);
}

function draw() {
}

function mouseDragged() {
  push();
  translate(mouseX-20, mouseY); 
  rotate(spin);
  ellipse(0, 0, 80, 20); 
  pop();
 
  push();
  translate(mouseX+20, mouseY); 
  rotate(spin);
  ellipse(0, 0, 80, 20); 
  pop();

  spin+=0.1;
}

function keyPressed() {
  background(255);
}

```

Here’s the Processing sketch:

```auto
float spin;

void setup() {
  size(400, 400);
  background(255);
}

void draw() {
}

void mouseDragged() {
  pushMatrix();
  translate(mouseX-20, mouseY); 
  rotate(spin);
  ellipse(0, 0, 80, 20); 
  popMatrix();
 
  pushMatrix();
  translate(mouseX+20, mouseY); 
  rotate(spin);
  ellipse(0, 0, 80, 20); 
  popMatrix();

  spin+=0.1;
}

void keyPressed() {
  background(255);
}

```

---

<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:** [July 29, 2019, 7:19pm UTC](https://discourse.processing.org/t/translation-from-processing-to-p5-not-working/13051/2 "2019-07-29T19:19:08Z")

</div>

> [@SheCurvesMobius](#):
>
> `var spin;`

> [@SheCurvesMobius](#):
>
> `float spin;`

> [@SheCurvesMobius](#):
>
> `spin += 0.1;`

- In Java, fields are automatically initialized w/ a default value according to their datatype.
- For `float`, that default value is `0.0f`.
- However in JS, the initial value for all variables is `undefined`.
- And when they’re coerced to a numerical value, like you do at `spin += 0.1;`, they become `NaN`.
- In order to avoid that, initialize the _spin_ variable: `let spin = 0;`

---

<div class="post-metadata">

**Author:** ![SheCurvesMobius](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/shecurvesmobius/32/7054_2.png) [@SheCurvesMobius](https://discourse.processing.org/u/SheCurvesMobius)\
**Post date:** [July 29, 2019, 7:22pm UTC](https://discourse.processing.org/t/translation-from-processing-to-p5-not-working/13051/3 "2019-07-29T19:22:14Z")

</div>

Amazing! Thanks so much, that’s extremely helpful!
