# Problem with code p5js

**URL:** https://discourse.processing.org/t/problem-with-code-p5js/11379
**Category:** Beginners
**Created:** [May 19, 2019, 11:42am UTC](https://discourse.processing.org/t/problem-with-code-p5js/11379 "2019-05-19T11:42:40Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![bitCrasher](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/bitcrasher/32/408_2.png) [@bitCrasher](https://discourse.processing.org/u/bitCrasher)
#### Post date: [May 19, 2019, 11:42am UTC](https://discourse.processing.org/t/problem-with-code-p5js/11379/1 "2019-05-19T11:42:40Z")

</div>

hello!  
i’m trying to rewrite this code in processing:  
[https://www.openprocessing.org/sketch/617540](https://www.openprocessing.org/sketch/617540)

but there is a part i don’t understand  
row 8:  
`noiseSeed = noiseSeed || 1`

this code pass to block function an int:

```auto
	for(var i=0;i<3;i++){
		push()
			translate(width/2 - (i-1)*(height-60),height/2)
			Block(i)
		pop()
		
	}

```

but if i try to do the same in processing i con’t…how i have to convert this operation?  
thank you for the answer!

---

<div class="post-metadata">

### Author: ![humayung](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/humayung/32/6089_2.png) [@humayung](https://discourse.processing.org/u/humayung)
#### Post date: [May 19, 2019, 11:54am UTC](https://discourse.processing.org/t/problem-with-code-p5js/11379/2 "2019-05-19T11:54:00Z")

</div>

```auto
noiseSeed = noiseSeed || 1

```

The `noiseSeed` will be 1 if previous `noiseSeed` is 0.  
So that line preventing `noiseSeed` become 0.

the `||` symbol means `or` operation. it behaves different to each data type. for example  
let `stringA` is a string  
`stringA = stringA || "ABCD"`  
if `stringA` is empty it will returns “ABCD” otherwise no changes.

for object, it will check if it `null` or not

in processing, you can change that line to  
`noiseSeed = noiseSeed == 0 ? 1 : noiseSeed;`

---

<div class="post-metadata">

### Author: ![bitCrasher](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/bitcrasher/32/408_2.png) [@bitCrasher](https://discourse.processing.org/u/bitCrasher)
#### Post date: [May 19, 2019, 12:00pm UTC](https://discourse.processing.org/t/problem-with-code-p5js/11379/3 "2019-05-19T12:00:38Z")

</div>

really thank you!  
but the code still doesn’t work

```auto

float counter = 1;

void setup() {
  size(1920, 1080, P2D);
  background(0);
}

void draw() {
  background(0);
  for (int i=0; i<3; i++) {
    pushMatrix();
    translate(width/2 - (i-1)*(height-60), height/2);
    Block(i);
    popMatrix();
  }

  pushMatrix();
  stroke(255);
  strokeWeight(2);
  line(0, 10, width, 10);
  line(0, height-10, width, height-10);
  popMatrix();
}

void Block(int noiseSeed) {
  noiseSeed = noiseSeed == 0 ? 1 : noiseSeed;

  if (frameCount>100) {
    counter = lerp(counter, 200, 0.1);
  }
  
  int selected = int(noise(frameCount/400, noiseSeed)*100);
  for (int i=0; i<100; i++) {

    pushMatrix();

    float ang = noise(frameCount/500, i, noiseSeed*100)* 3 * PI + noiseSeed*10;
    float r = counter;
    PVector p =new PVector(1, 1).mult(r).rotate(ang);

    fill(255);
    if (i==selected) {
      fill(255, 0, 0);
    }
    stroke(255, 70);
    line(0, 0, p.x, p.y);
    noStroke();
    rect(p.x, p.y, 5, 5);

    if (i==selected) {
      pushMatrix();
      translate(p.x, p.y);
      rect(20, 0, 40, 3);
      rect(20, 10, 15, 3);
      rect(20, 20, 65, 3);
      text("POZ: "+ int(p.x)+ ", " + int(p.y) + "<"+ang, 20, 50);
      popMatrix();
    }
    popMatrix();
  }

  stroke(255);
  noFill();
  ellipse(0, 0, 50, 50);
  textSize(10);
  text("TARGET #ID: "+selected, 20, 20);

  if (frameCount % 200 <30) {
    if (frameCount % 4<2) {
      background(255);
    } else {
      // background(0)
    }
  }

  int edge = height - 100;
  stroke(255) ;
  rect(-edge/2, -edge/2, edge, edge);

  edge = height - 80;
  stroke(255, 30);

  rect(-edge/2, -edge/2, edge, edge);

  noStroke();
  fill(255);
  textSize(12);
  text("EXPR#"+noiseSeed, -edge/2, -edge/2+ 10);
}

```

what’s wrong?

---

<div class="post-metadata">

### Author: ![humayung](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/humayung/32/6089_2.png) [@humayung](https://discourse.processing.org/u/humayung)
#### Post date: [May 19, 2019, 12:24pm UTC](https://discourse.processing.org/t/problem-with-code-p5js/11379/4 "2019-05-19T12:24:19Z")

</div>

frameCount is an integer. try to cast it to float first on line 32 and 27

> <https://stackoverflow.com/questions/4377842/how-can-i-convert-integer-into-float-in-java>

---

<div class="post-metadata">

### Author: ![bitCrasher](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/bitcrasher/32/408_2.png) [@bitCrasher](https://discourse.processing.org/u/bitCrasher)
#### Post date: [May 19, 2019, 12:48pm UTC](https://discourse.processing.org/t/problem-with-code-p5js/11379/5 "2019-05-19T12:48:37Z")

</div>

ok…just converted every frameCount…now it works…thank you so much

---

<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: [May 19, 2019, 12:54pm UTC](https://discourse.processing.org/t/problem-with-code-p5js/11379/6 "2019-05-19T12:54:03Z")

</div>

> [@bitCrasher](#):
>
> `frameCount/400`

In order to avoid an integer division in Java, at least 1 of the operands gotta be a floating value: `frameCount/400.0`
