Problem with code p5js

hello!
i’m trying to rewrite this code in processing:
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:

	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!

1 Like
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;

1 Like

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


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?

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

1 Like

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

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

2 Likes