initVariables();
xp = 0;
yp = 0;
rp = 50;
numSpheres = 12; // Número de esfera
pos = 0;
ocupado = false;
nCoefi = 2.80;
nDedo = 3;
////////////////////////////////////////////////////////
function funcionGo(ctx, width, height) {
  if (lInit) {
    jsreinitProcedure();
    jsinitTimer(30);
    posSpheres = [];
    xp = random(wsIni + rp / 2, wsIni + wVideo - rp / 2);
    yp = random(hsIni + rp / 2, hsIni + hVideo - rp / 2);
    ellipse(xp, yp, rp * 2, rp * 2);
    txClocalUp = "OPOSICION DEL PULGAR/PALMA ABIERTA";
    txClocalDown = "Apunte al numero con el pulgar";
    centerX = windowWidth / 2;
    centerY = windowHeight / 2; // Centro del lienzo
    radius = windowHeight;
    if (deviceAndroid) {
      _handleMotion();
      if (deviceOrientation == "portrait") {
        if (lChangeCam) radius = windowHeight - 120;
        nCoefi = 3.10;
      } else {
        if (deviceOrientation == "landscape") {
          nCoefi = 1.90;
        }
      }
    }
    for (let i = 0; i < numSpheres; i++) {
      let angle = map(i, 0, numSpheres, 0, TWO_PI); // Ángulo en radianes
      let x = centerX + (radius / nCoefi) * cos(angle); // Coordenada x
      let y = centerY + (radius / nCoefi) * sin(angle); // Coordenada y
      let value = false;
      addPoint(x, y, value);
    }
    let num = random(0, 11);
    pos = parseInt(num);
    posSpheres[pos].value = true;
    ocupado = true;
  }
  //displaymodulo(0);
  strokeWeight(1);
  noStroke()
  noFill();
  ellipse(centerX, centerY, radius);
  //stroke(155, 155, 155, 128);
  let uno = 0;
  for (let i = 0; i < numSpheres; i++) {
    if (posSpheres[i].value) uno++;
    if (posSpheres[i].value) fill(255, 0, 0, 128);
    else fill(128, 128, 128, 128);
    if (uno > 1) {
      posSpheres[i].value = false;
      fill(128, 128, 128, 128);
    }
    //ellipse(posSpheres[i].x, posSpheres[i].y, rp * 2, rp * 2);
    // Dibujar el número romano dentro del círculo
    fill(0);
    textAlign(CENTER, CENTER);
    textSize(28);
    fill(255);
    //text(toRoman(i), posSpheres[i].x, posSpheres[i].y);
    textSize(12);
  }

  textSize(96);
  fill(255);
  text(nDedo, wsIni + wVideo / 2, hsIni + 100);

  fill(255, 0, 0, 128);
  ellipse(pCfbr4.x, pCfbr4.y, rp, rp);
  ///////////////////////////////////
  /*ellipse(pCfbr7.x, pCfbr7.y, rp / 2, rp / 2);
  ellipse(pCfbr11.x, pCfbr11.y, rp / 2, rp / 2);
  ellipse(pCfbr15.x, pCfbr15.y, rp / 2, rp / 2);
  ellipse(pCfbr19.x, pCfbr19.y, rp / 2, rp / 2);*/

  ellipse(pCfbr6.x, pCfbr6.y, rp, rp);
  ellipse(pCfbr10.x, pCfbr10.y, rp, rp);
  ellipse(pCfbr14.x, pCfbr14.y, rp, rp);
  ellipse(pCfbr18.x, pCfbr18.y, rp, rp);
  /////////////////////////////////////
  ellipse(pCfbl4.x, pCfbl4.y, rp, rp);

  /*ellipse(pCfbl7.x, pCfbl7.y, rp, rp);
  ellipse(pCfbl11.x, pCfbl11.y, rp, rp);
  ellipse(pCfbl15.x, pCfbl15.y, rp, rp);
  ellipse(pCfbl19.x, pCfbl19.y, rp, rp);*/

  ellipse(pCfbl6.x, pCfbl6.y, rp, rp);
  ellipse(pCfbl10.x, pCfbl10.y, rp, rp);
  ellipse(pCfbl14.x, pCfbl14.y, rp, rp);
  ellipse(pCfbl18.x, pCfbl18.y, rp, rp);

  /////////////////////////////////////
  textSize(22);
  fill(255);
  /*text(1, pCfbr7.x, pCfbr7.y);
  text(2, pCfbr11.x, pCfbr11.y);
  text(3, pCfbr15.x, pCfbr15.y);
  text(4, pCfbr19.x, pCfbr19.y);*/

  text(1, pCfbr4.x, pCfbr4.y);
  text(2, pCfbr6.x, pCfbr6.y);
  text(3, pCfbr10.x, pCfbr10.y);
  text(4, pCfbr14.x, pCfbr14.y);
  text(5, pCfbr18.x, pCfbr18.y);

  /*text(1, pCfbl7.x, pCfbl7.y);
  text(2, pCfbl11.x, pCfbl11.y);
  text(3, pCfbl15.x, pCfbl15.y);
  text(4, pCfbl19.x, pCfbl9.y);*/

  text(1, pCfbl4.x, pCfbl4.y);
  text(2, pCfbl6.x, pCfbl6.y);
  text(3, pCfbl10.x, pCfbl10.y);
  text(4, pCfbl14.x, pCfbl14.y);
  text(5, pCfbl18.x, pCfbl18.y);

  /////////////////////////////////////////
  textSize(12);

  /*if (dist(posSpheres[pos].x, posSpheres[pos].y, pCW1.x, pCW1.y) < rp * 2 || dist(posSpheres[pos].x, posSpheres[pos].y, pCW2.x, pCW2.y) < rp * 2) {
    posSpheres[pos].value = false;
    ocupado = false;
  }
  if (!ocupado) {
    let num = random(0, 11);
    pos = parseInt(num);
    posSpheres[pos].value = true;
    ocupado = true;
  }*/
  if (lDelayLocal) {
    nDedo = int(random(2, 5));
  }
  pCW1.x = -width;
  pCW1.y = -width;
  pCW2.x = -width;
  pCW2.x = -width;

  pCfbr4.x = -width;
  pCfbr4.y = -width;

  pCfbr5.x = -width;
  pCfbr5.y = -width;
  pCfbr9.x = -width;
  pCfbr9.y = -width;
  pCfbr13.x = -width;
  pCfbr13.y = -width;
  pCfbr17.x = -width;
  pCfbr17.y = -width;

  pCfbr6.x = -width;
  pCfbr6.y = -width;
  pCfbr10.x = -width;
  pCfbr10.y = -width;
  pCfbr14.x = -width;
  pCfbr14.y = -width;
  pCfbr18.x = -width;
  pCfbr18.y = -width;

  pCfbl4.x = -width;
  pCfbl4.y = -width;

  pCfbl5.x = -width;
  pCfbl5.y = -width;
  pCfbl9.x = -width;
  pCfbl9.y = -width;
  pCfbl13.x = -width;
  pCfbl13.y = -width;
  pCfbl17.x = -width;
  pCfbl17.y = -width;

  pCfbl6.x = -width;
  pCfbl6.y = -width;
  pCfbl10.x = -width;
  pCfbl10.y = -width;
  pCfbl14.x = -width;
  pCfbl14.y = -width;
  pCfbl18.x = -width;
  pCfbl18.y = -width;
}
///////////////////////////
function addPoint(x, y, value) {
  let point = { x: x, y: y, value: value };
  posSpheres.push(point);
}
function toRoman(num) {
  const romanNumerals = ["III", "IV", "V", "VI", "VII", "VIII", "IX", "X", "XI", "XII", "I", "II"];
  //const romanNumerals = ["4", "5", "6", "7", "8", "9", "10", "11", "12", "1", "2", "3"];
  return romanNumerals[num % 12]; // Devolver el número romano correspondiente
}