beginShape()+ for loop + PVector running in Java but not in JavaScript mode.

edited February 2015 in JavaScript Mode

Hi, I have this small piece of code that runs fine in processing java mode but not in java script mode. Can any one help me figure it out what is happening?

PVector vertice[] = new PVector[6];
void setup() {
  size(200, 200);
  background(255);
}

void draw() {
}

void mouseClicked() {
  background(255);
  sorteiaPontos();
  desenhaCurvas();
}

void desenhaCurvas() {
  translate(width/2, height/2);
  noFill();

  beginShape();
  curveVertex(vertice[5].x, vertice[5].y);  
  for (int i=0; i<6; i++) {
    curveVertex(vertice[i].x, vertice[i].y);
  }
  curveVertex(vertice[0].x, vertice[0].y);
  curveVertex(vertice[1].x, vertice[1].y);
  endShape();
}

void sorteiaPontos() {
  for (int i=0; i<6; i++) {
    vertice[i]= PVector.random2D();
    vertice[i].mult(width/3);
  }
}

Thanks.

Answers

  • edited February 2015 Answer ✓

    Method random2D() which instantiates a new PVector w/ random values within 0 & 1 range,
    is still unimplemented in PJS framework (JS Mode): http://processingjs.org/reference/PVector/

    When developing for PJS deployment, it's more guaranteed to use old Processing v1.5.1.
    B/c it matches PJS API state better! PJS still lacks many Processing 2/3 features! X_X

  • edited February 2015 Answer ✓

    As a replacement for PVector.random2D(), go w/ new PVector(random(1), random(1)); ;)

    P.S.: "p5.js" is the wrong category for your question!
    Shoulda been "Questions about Modes" -> "JavaScript Mode".
    You can re-edit it at any time though! B-)

  • thanks, GoToLoop. I worked it up slowly straight on javascript, now it's running fine.

Sign In or Register to comment.