initVariables();
//////////////////////////////////
function funcionGo(ctx, width, height) {
  if (lInit) {
    jsreinitProcedure();
    jsinitTimer(1);
    txClocalUp = "IA PARA LA POSTURA";
    txClocalDown = "sepárese un poco de la cámara";
    //lHandline = true;
    //lHandjoint = true;
  }
  //displaymodulo(0);
  displayPose();
  noStroke();
}

function displayPose() {
  let angle = 0;
  textSize(20)


  ////////////////// stroke( 252, 208, 180, 128 ) color carne
  strokeWeight(10)
  stroke(242, 240, 235, 128)
  noFill() //fill(252, 208, 180, 128);

  //cabeza
  /*beginShape();
  //curveVertex((x11 + x12) / 2, (y11 + y12) / 2)
  curveVertex(x9, y9);
  curveVertex(x0, y0);
  curveVertex(x1, y1);
  curveVertex(x2, y2);
  curveVertex(x3, y3);
  curveVertex(x7, y7);
  curveVertex(x0, y0);
  curveVertex(x10, y10);
  //curveVertex((x11 + x12) / 2, (y11 + y12) / 2)
  endShape();

  beginShape();
  //curveVertex((x11 + x12) / 2, (y11 + y12) / 2)
  curveVertex(x10, y10);
  curveVertex(x0, y0);
  curveVertex(x4, y4);
  curveVertex(x5, y5);
  curveVertex(x6, y6);
  curveVertex(x8, y8);
  curveVertex(x0, y0);
  curveVertex(x9, y9);
  //curveVertex((x11 + x12) / 2, (y11 + y12) / 2)
  endShape();*/

  if (!modoReflejo) {

    noStroke();
    fill(0);
    let rshoulder = [x12, y12]
    let relbow = [x14, y14]
    let rwrist = [x16, y16]
    angle = calculate_angle(rshoulder, relbow, rwrist)
    text(parseInt(angle), x14, y14)

    let lshoulder = [x11, y11]
    let lelbow = [x13, y13]
    let lwrist = [x15, y15]
    angle = calculate_angle(lshoulder, lelbow, lwrist)
    text(parseInt(angle), x13, y13)

    let rhip = [x24, y24]
    angle = calculate_angle(rhip, rshoulder, relbow)
    text(parseInt(angle), x12, y12)

    let lhip = [x23, y23]
    angle = calculate_angle(lhip, lshoulder, lelbow)
    text(parseInt(angle), x11, y11)

    let rknee = [x26, y26]
    let rankle = [x28, y28]
    angle = calculate_angle(rhip, rknee, rankle)
    text(parseInt(angle), x26, y26)

    let lknee = [x25, y25]
    let lankle = [x27, y27]
    angle = calculate_angle(lhip, lknee, lankle)
    text(parseInt(angle), x25, y25)

    angle = calculate_angle(lshoulder, lhip, lknee)
    text(parseInt(angle), x23, y23)

    angle = calculate_angle(rshoulder, rhip, rknee)
    text(parseInt(angle), x24, y24)

    let lfoot = [x31, y31]
    angle = calculate_angle(lknee, lankle, lfoot)
    text(parseInt(angle), x27, y27)

    let rfoot = [x32, y32]
    angle = calculate_angle(rknee, rankle, rfoot)
    text(parseInt(angle), x28, y28)

    strokeWeight(10)
    stroke(242, 240, 235, 128)
    noFill() //fill(252, 208, 180, 128);; //noFill()

    //eess
    beginShape();
    curveVertex(x0, y0);
    curveVertex((x11 + x12) / 2, (y11 + y12) / 2)
    curveVertex((x11 + (x11 + x12) / 2) / 2, (y11 + (y11 + y12) / 2) / 2)
    curveVertex(x11, y11);
    curveVertex(x13, y13);
    curveVertex(x15, y15);
    curveVertex(x17, y17);
    curveVertex(x19, y19);
    curveVertex(x21, y21);
    curveVertex(x15, y15);
    curveVertex(x13, y13);
    curveVertex((x11 + (x11 + x12) / 2) / 2, (y11 + (y11 + y12) / 2) / 2)
    curveVertex(x12, y12);
    endShape();

    beginShape();
    curveVertex(x0, y0);
    curveVertex((x11 + x12) / 2, (y11 + y12) / 2)
    curveVertex((x12 + (x11 + x12) / 2) / 2, (y12 + (y11 + y12) / 2) / 2)
    curveVertex(x12, y12);
    curveVertex(x14, y14);
    curveVertex(x16, y16);
    curveVertex(x18, y18);
    curveVertex(x20, y20);
    curveVertex(x22, y22);
    curveVertex(x16, y16);
    curveVertex(x14, y14);
    curveVertex((x12 + (x11 + x12) / 2) / 2, (y12 + (y11 + y12) / 2) / 2)
    curveVertex((x11 + x12) / 2, (y11 + y12) / 2)
    endShape();

    //eeii
    beginShape();
    curveVertex((x23 + x24) / 2, (y23 + y24) / 2);
    curveVertex(x23, y23);
    curveVertex(x25, y25);
    curveVertex(x27, y27);
    curveVertex(x29, y29);
    curveVertex(x31, y31);
    curveVertex(x27, y27);
    curveVertex(x25, y25);
    curveVertex((x23 + x24) / 2, (y23 + y24) / 2);
    curveVertex(x24, y24);
    endShape();

    beginShape();
    curveVertex((x23 + x24) / 2, (y23 + y24) / 2);
    curveVertex(x24, y24);
    curveVertex(x26, y26);
    curveVertex(x28, y28);
    curveVertex(x30, y30);
    curveVertex(x32, y32);
    curveVertex(x28, y28);
    curveVertex(x26, y26);
    curveVertex((x23 + x24) / 2, (y23 + y24) / 2);
    curveVertex(x23, y23);
    endShape();

    //tronco
    beginShape();
    curveVertex(x0, y0);
    //curveVertex((x11+x12)/2, (y11+y12)/2)
    curveVertex(x11, y11);
    curveVertex((x11 + (x23 + x24) / 2) / 2, (y11 + (y23 + y24) / 2) / 2)
    curveVertex(x23, y23);
    curveVertex(x24, y24);
    //curveVertex((x23+x24)/2, (y23+y24)/2)
    endShape();

    beginShape();
    curveVertex(x0, y0);
    //curveVertex((x11+x12)/2, (y11+y12)/2)
    curveVertex(x12, y12);
    curveVertex((x12 + (x23 + x24) / 2) / 2, (y12 + (y23 + y24) / 2) / 2)
    curveVertex(x24, y24);
    curveVertex(x23, y23);
    //curveVertex((x23+x24)/2, (y23+y24)/2)
    endShape();
  }

  else {
    if (modoDiestro) {
      noStroke();
      fill(0);
      let rshoulder = [x12, y12]
      let relbow = [x14, y14]
      let rwrist = [x16, y16]
      angle = calculate_angle(rshoulder, relbow, rwrist)
      text(parseInt(angle), x14, y14)

      let rhip = [x24, y24]
      angle = calculate_angle(rhip, rshoulder, relbow)
      text(parseInt(angle), x12, y12)

      let rknee = [x26, y26]
      let rankle = [x28, y28]
      angle = calculate_angle(rhip, rknee, rankle)
      text(parseInt(angle), x26, y26)

      angle = calculate_angle(rshoulder, rhip, rknee)
      text(parseInt(angle), x24, y24)

      let rfoot = [x32, y32]
      angle = calculate_angle(rknee, rankle, rfoot)
      text(parseInt(angle), x28, y28)

      strokeWeight(10)
      stroke(242, 240, 235, 128)
      noFill() //fill(252, 208, 180, 128);; //noFill()

      beginShape();
      curveVertex(x0, y0);
      curveVertex((x11 + x12) / 2, (y11 + y12) / 2)
      curveVertex((x12 + (x11 + x12) / 2) / 2, (y12 + (y11 + y12) / 2) / 2)
      curveVertex(x12, y12);
      curveVertex(x14, y14);
      curveVertex(x16, y16);
      curveVertex(x18, y18);
      curveVertex(x20, y20);
      curveVertex(x22, y22);
      curveVertex(x16, y16);
      curveVertex(x14, y14);
      curveVertex((x12 + (x11 + x12) / 2) / 2, (y12 + (y11 + y12) / 2) / 2)
      curveVertex((x11 + x12) / 2, (y11 + y12) / 2)
      endShape();
      beginShape();
      curveVertex(width - x0, y0);
      curveVertex(width - (x11 + x12) / 2, (y11 + y12) / 2)
      curveVertex(width - (x12 + (x11 + x12) / 2) / 2, (y12 + (y11 + y12) / 2) / 2)
      curveVertex(width - x12, y12);
      curveVertex(width - x14, y14);
      curveVertex(width - x16, y16);
      curveVertex(width - x18, y18);
      curveVertex(width - x20, y20);
      curveVertex(width - x22, y22);
      curveVertex(width - x16, y16);
      curveVertex(width - x14, y14);
      curveVertex(width - (x12 + (x11 + x12) / 2) / 2, (y12 + (y11 + y12) / 2) / 2)
      curveVertex(width - (x11 + x12) / 2, (y11 + y12) / 2)
      endShape();

      strokeWeight(10)
      stroke(242, 240, 235, 128)
      noFill() //fill(252, 208, 180, 128);; //noFill()

      //eeii
      beginShape();
      curveVertex((x23 + x24) / 2, (y23 + y24) / 2);
      curveVertex(x24, y24);
      curveVertex(x26, y26);
      curveVertex(x28, y28);
      curveVertex(x30, y30);
      curveVertex(x32, y32);
      curveVertex(x28, y28);
      curveVertex(x26, y26);
      curveVertex((x23 + x24) / 2, (y23 + y24) / 2);
      curveVertex(x23, y23);
      endShape();

      beginShape();
      curveVertex(width - (x23 + x24) / 2, (y23 + y24) / 2);
      curveVertex(width - x24, y24);
      curveVertex(width - x26, y26);
      curveVertex(width - x28, y28);
      curveVertex(width - x30, y30);
      curveVertex(width - x32, y32);
      curveVertex(width - x28, y28);
      curveVertex(width - x26, y26);
      curveVertex(width - (x23 + x24) / 2, (y23 + y24) / 2);
      curveVertex(width - x23, y23);
      endShape();

      //tronco
      beginShape();
      curveVertex(x0, y0);
      //curveVertex((x11+x12)/2, (y11+y12)/2)
      curveVertex(x12, y12);
      curveVertex((x12 + (x23 + x24) / 2) / 2, (y12 + (y23 + y24) / 2) / 2)
      curveVertex(x24, y24);
      curveVertex(x23, y23);
      //curveVertex((x23+x24)/2, (y23+y24)/2)
      endShape();

      beginShape();
      curveVertex(width - x0, y0);
      //curveVertex((x11+x12)/2, (y11+y12)/2)
      curveVertex(width - x12, y12);
      curveVertex(width - (x12 + (x23 + x24) / 2) / 2, (y12 + (y23 + y24) / 2) / 2)
      curveVertex(width - x24, y24);
      curveVertex(width - x23, y23);
      //curveVertex((x23+x24)/2, (y23+y24)/2)
      endShape();
    }
    else {
      noStroke();
      fill(0);

      let lshoulder = [x11, y11]
      let lelbow = [x13, y13]
      let lwrist = [x15, y15]
      angle = calculate_angle(lshoulder, lelbow, lwrist)
      text(parseInt(angle), x13, y13)

      let lhip = [x23, y23]
      angle = calculate_angle(lhip, lshoulder, lelbow)
      text(parseInt(angle), x11, y11)

      let lknee = [x25, y25]
      let lankle = [x27, y27]
      angle = calculate_angle(lhip, lknee, lankle)
      text(parseInt(angle), x25, y25)

      angle = calculate_angle(lshoulder, lhip, lknee)
      text(parseInt(angle), x23, y23)

      let lfoot = [x31, y31]
      angle = calculate_angle(lknee, lankle, lfoot)
      text(parseInt(angle), x27, y27)

      strokeWeight(10)
      stroke(242, 240, 235, 128)
      noFill() //fill(252, 208, 180, 128);; //noFill()

      beginShape();
      curveVertex(x0, y0);
      curveVertex((x11 + x12) / 2, (y11 + y12) / 2)
      curveVertex((x11 + (x11 + x12) / 2) / 2, (y11 + (y11 + y12) / 2) / 2)
      curveVertex(x11, y11);
      curveVertex(x13, y13);
      curveVertex(x15, y15);
      curveVertex(x17, y17);
      curveVertex(x19, y19);
      curveVertex(x21, y21);
      curveVertex(x15, y15);
      curveVertex(x13, y13);
      curveVertex((x11 + (x11 + x12) / 2) / 2, (y11 + (y11 + y12) / 2) / 2)
      curveVertex(x12, y12);
      endShape();

      beginShape();
      curveVertex(width - x0, y0);
      curveVertex(width - (x11 + x12) / 2, (y11 + y12) / 2)
      curveVertex(width - (x11 + (x11 + x12) / 2) / 2, (y11 + (y11 + y12) / 2) / 2)
      curveVertex(width - x11, y11);
      curveVertex(width - x13, y13);
      curveVertex(width - x15, y15);
      curveVertex(width - x17, y17);
      curveVertex(width - x19, y19);
      curveVertex(width - x21, y21);
      curveVertex(width - x15, y15);
      curveVertex(width - x13, y13);
      curveVertex(width - (x11 + (x11 + x12) / 2) / 2, (y11 + (y11 + y12) / 2) / 2)
      curveVertex(width - x12, y12);
      endShape();

      strokeWeight(10)
      stroke(242, 240, 235, 128)
      noFill() //fill(252, 208, 180, 128); //noFill()

      beginShape();
      curveVertex((x23 + x24) / 2, (y23 + y24) / 2);
      curveVertex(x23, y23);
      curveVertex(x25, y25);
      curveVertex(x27, y27);
      curveVertex(x29, y29);
      curveVertex(x31, y31);
      curveVertex(x27, y27);
      curveVertex(x25, y25);
      curveVertex((x23 + x24) / 2, (y23 + y24) / 2);
      curveVertex(x24, y24);
      endShape();

      beginShape();
      curveVertex(width - (x23 + x24) / 2, (y23 + y24) / 2);
      curveVertex(width - x23, y23);
      curveVertex(width - x25, y25);
      curveVertex(width - x27, y27);
      curveVertex(width - x29, y29);
      curveVertex(width - x31, y31);
      curveVertex(width - x27, y27);
      curveVertex(width - x25, y25);
      curveVertex(width - (x23 + x24) / 2, (y23 + y24) / 2);
      curveVertex(width - x24, y24);
      endShape();

      beginShape();
      curveVertex(x0, y0);
      //curveVertex((x11+x12)/2, (y11+y12)/2)
      curveVertex(x11, y11);
      curveVertex((x11 + (x23 + x24) / 2) / 2, (y11 + (y23 + y24) / 2) / 2)
      curveVertex(x23, y23);
      curveVertex(x24, y24);
      //curveVertex((x23+x24)/2, (y23+y24)/2)
      endShape();

      beginShape();
      curveVertex(width - x0, y0);
      //curveVertex((x11+x12)/2, (y11+y12)/2)
      curveVertex(width - x11, y11);
      curveVertex(width - (x11 + (x23 + x24) / 2) / 2, (y11 + (y23 + y24) / 2) / 2)
      curveVertex(width - x23, y23);
      curveVertex(width - x24, y24);
      //curveVertex((x23+x24)/2, (y23+y24)/2)
      endShape();
    }
  }
}