initVariables();
function funcionGo(ctx, width, height) {
  if (lInit) {
    jsreinitProcedure();
    jsinitTimer(5);
    txClocalUp = "CENTIMETRIA DE CABEZA/CUELLO";
    txClocalDown = "sepárese de la cámara, la cara debe activarse";
  }
  //displaymodulo(0);
  displayPose();

  noStroke();
}

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

  strokeWeight(20)
  stroke(255, 255, 255, 128)
  fill(255, 255, 255, 128);
  noFill();
  //noStroke();
  //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(x9, y9);
  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(x10, y10);
  curveVertex((x11 + x12) / 2, (y11 + y12) / 2)
  endShape();

  //cuello
  beginShape();
  curveVertex(x11, y11);
  curveVertex((x11 + (x11 + x12) / 2) / 2, (y11 + (y11 + y12) / 2) / 2)
  //curveVertex(x9, y9);
  //curveVertex(x0, y0);
  //curveVertex(x1, y1);
  //curveVertex(x2, y2);
  //curveVertex(x3, y3);
  //curveVertex(x7, y7);
  //curveVertex(x0, y0);
  //curveVertex(x9, y9);
  curveVertex((x11 + x12) / 2, (y11 + y12) / 2)
  //curveVertex((x11+(x11+x12)/2)/2, (y11+(y11+y12)/2)/2)
  curveVertex(x11, y11);
  curveVertex(x13, y13);
  endShape();

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

  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)


  let loreja = [x7 - 25, y7]
  let cervical = [(x11 + x12) / 2, (y11 + y12) / 2]
  angle = calculate_angle(loreja, cervical, lshoulder)
  //text(parseInt(angle), x7, y7)

  let roreja = [x8 + 25, y8]
  angle = calculate_angle(roreja, cervical, rshoulder)
  //text(parseInt(angle), x8, y8)

  let nariz = [x0, y0]
  angle = calculate_angle(nariz, cervical, lshoulder)
  //text(parseInt(angle), x9, y9)

  angle = calculate_angle(nariz, cervical, rshoulder)
  //text(parseInt(angle), x10, y10)

  let entrecejo = [(x4 + x1) / 2, (y4 + y1) / 2]
  angle = calculate_angle(entrecejo, nariz, cervical)
  //text(parseInt(angle), (x11 + x12) / 2, (y11 + y12) / 2)

  let rp = 20;

  strokeWeight(2)
  stroke(255, 255, 255, 128)
  fill(255, 255, 255, 128);

  line(x7 - 25, y7, x11, y11)
  ellipse(x7 - 25, y7, rp)
  ellipse(x11, y11, rp)

  line(x8 + 25, y8, x12, y12)
  ellipse(x8 + 25, y8, rp)
  ellipse(x12, y12, rp)

  line((((x11 + x12) / 2) + x0) / 2, (((y11 + y12) / 2) + y0) / 2, (x11 + x12) / 2, (y11 + y12) / 2)
  ellipse((((x11 + x12) / 2) + x0) / 2, (((y11 + y12) / 2) + y0) / 2, rp)
  ellipse((x11 + x12) / 2, (y11 + y12) / 2, rp)

  //stroke(0, 255, 0, 128);
  line((((x11 + x12) / 2) + x0) / 2 - 50, (((y11 + y12) / 2) + y0) / 2, x11, y11)
  ellipse((((x11 + x12) / 2) + x0) / 2 - 50, (((y11 + y12) / 2) + y0) / 2, rp)

  line((((x11 + x12) / 2) + x0) / 2 + 50, (((y11 + y12) / 2) + y0) / 2, x12, y12)
  ellipse((((x11 + x12) / 2) + x0) / 2 + 50, (((y11 + y12) / 2) + y0) / 2, rp)

  strokeWeight(8)
  stroke(255, 0, 0, 128)
  fill(255, 0, 0);
  switch (nSwitch) {
    case 0:
      txClocalUp = "FLEXIÓN DE CABEZA";
      txClocalDown = "baje la cabeza/menton";
      line((((x11 + x12) / 2) + x0) / 2, (((y11 + y12) / 2) + y0) / 2, (x11 + x12) / 2, (y11 + y12) / 2)
      break;
    case 1:
      txClocalUp = "ROTACIÓN IZQUIERDA";
      txClocalDown = "gire la cabeza a la izquierda";
      line((((x11 + x12) / 2) + x0) / 2 - 50, (((y11 + y12) / 2) + y0) / 2, x11, y11)
      break;
    case 2:
      txClocalUp = "ROTACIÓN DERECHA";
      txClocalDown = "gire la cabeza a la derecha";
      line((((x11 + x12) / 2) + x0) / 2 + 50, (((y11 + y12) / 2) + y0) / 2, x12, y12)
      break;
    case 3:
      txClocalUp = "LATERALIZACIÓN IZQUIERDA";
      txClocalDown = "lateralice la cabeza a la izquierda";
      line(x7 - 25, y7, x11, y11)
      break;
    case 4:
      txClocalUp = "LATERALIZACIÓN DERECHA";
      txClocalDown = "lateralice la cabeza a la derecha";
      line(x8 + 25, y8, x12, y12)
      break;
  }
  noStroke();
  fill(0);

  let vMenton = createVector((((x11 + x12) / 2) + x0) / 2, (((y11 + y12) / 2) + y0) / 2);
  let vCervical = createVector((x11 + x12) / 2, (y11 + y12) / 2);

  let dwrMenton = abs(vMenton.dist(vCervical) / 10);
  text(parseInt(dwrMenton), ((((x11 + x12) / 2) + x0) / 2 + (x11 + x12) / 2) / 2, ((((y11 + y12) / 2) + y0) / 2 + (y11 + y12) / 2) / 2)

  let vHombroDch = createVector(x12, y12);
  let dwrMentonDch = abs(vMenton.dist(vHombroDch) / 14);
  text(parseInt(dwrMentonDch), (x12 + (((x11 + x12) / 2) + x0) / 2) / 2, (y12 + (((y11 + y12) / 2) + y0) / 2) / 2)

  let vHombroIzd = createVector(x11, y11);
  let dwrMentonIzd = abs(vMenton.dist(vHombroIzd) / 14);
  text(parseInt(dwrMentonIzd), (x11 + (((x11 + x12) / 2) + x0) / 2) / 2, (y11 + (((y11 + y12) / 2) + y0) / 2) / 2)

  let vOrejaDch = createVector(x8, y8);
  let dwrOrejaDch = abs(vOrejaDch.dist(vHombroDch) / 14);
  text(parseInt(dwrOrejaDch), (x8 + x12) / 2 + 25, (y8 + y12) / 2)

  let vOrejaIzd = createVector(x7, y7);
  let dwrOrejaIzd = abs(vOrejaIzd.dist(vHombroIzd) / 14);
  text(parseInt(dwrOrejaIzd), (x7 + x11) / 2 - 25, (y7 + y11) / 2)
}