initVariables();
xp = 0;
yp = 0;
rp = 50;
numSpheres = 12; // Número de esferas
pos = 0;
ocupado = false;
nCoefi = 2.80;
nDedo = 0;
////////////////////////////////////////////////////////
function funcionGo(ctx, width, height) {
  if (lInit) {
    jsreinitProcedure();
    jsinitTimer(10);
    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";
    txClocalDown = "Apunte a cada 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);
      console.info(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(pCfbr5.x, pCfbr5.y, rp / 2, rp / 2);
  ellipse(pCfbr6.x, pCfbr6.y, rp / 2, rp / 2);
  ellipse(pCfbr7.x, pCfbr7.y, rp / 2, rp / 2);
  ellipse(pCfbr8.x, pCfbr8.y, rp / 2, rp / 2);

  ellipse(pCfbr12.x, pCfbr12.y, rp / 2, rp / 2);
  ellipse(pCfbr16.x, pCfbr16.y, rp / 2, rp / 2);
  ellipse(pCfbr20.x, pCfbr20.y, rp / 2, rp / 2);

  ellipse(pCfbr19.x, pCfbr19.y, rp / 2, rp / 2);
  ellipse(pCfbr18.x, pCfbr18.y, rp / 2, rp / 2);
  ellipse(pCfbr17.x, pCfbr17.y, rp / 2, rp / 2);

  ellipse((pCfbr17.x + pCfbr5.x) / 2, (pCfbr2.y + pCfbr17.y) / 2, rp / 2, rp / 2);
  /////////////////////////////////////
  ellipse(pCfbl4.x, pCfbl4.y, rp, rp);

  ellipse(pCfbl5.x, pCfbl5.y, rp / 2, rp / 2);
  ellipse(pCfbl6.x, pCfbl6.y, rp / 2, rp / 2);
  ellipse(pCfbl7.x, pCfbl7.y, rp / 2, rp / 2);
  ellipse(pCfbl8.x, pCfbl8.y, rp / 2, rp / 2);

  ellipse(pCfbl12.x, pCfbl12.y, rp / 2, rp / 2);
  ellipse(pCfbl16.x, pCfbl16.y, rp / 2, rp / 2);
  ellipse(pCfbl20.x, pCfbl20.y, rp / 2, rp / 2);

  ellipse(pCfbl19.x, pCfbl19.y, rp / 2, rp / 2);
  ellipse(pCfbl18.x, pCfbl18.y, rp / 2, rp / 2);
  ellipse(pCfbl17.x, pCfbl17.y, rp / 2, rp / 2);

  ellipse((pCfbl17.x + pCfbl5.x) / 2, (pCfbl2.y + pCfbl17.y) / 2, rp / 2, rp / 2);
  /////////////////////////////////////
  textSize(18);
  fill(255);
  text(0, pCfbr5.x, pCfbr5.y);
  text(1, pCfbr6.x, pCfbr6.y);
  text(2, pCfbr7.x, pCfbr7.y);
  text(3, pCfbr8.x, pCfbr8.y);

  text(4, pCfbr12.x, pCfbr12.y);
  text(5, pCfbr16.x, pCfbr16.y);
  text(6, pCfbr20.x, pCfbr20.y);

  text(7, pCfbr19.x, pCfbr19.y);
  text(8, pCfbr18.x, pCfbr18.y);
  text(9, pCfbr17.x, pCfbr17.y);

  text(10, (pCfbr17.x + pCfbr5.x) / 2, (pCfbr2.y + pCfbr17.y) / 2);

  text(0, pCfbl5.x, pCfbl5.y);
  text(1, pCfbl6.x, pCfbl6.y);
  text(2, pCfbl7.x, pCfbl7.y);
  text(3, pCfbl8.x, pCfbl8.y);

  text(4, pCfbl12.x, pCfbl12.y);
  text(5, pCfbl16.x, pCfbl16.y);
  text(6, pCfbl20.x, pCfbl20.y);

  text(7, pCfbl19.x, pCfbl19.y);
  text(8, pCfbl18.x, pCfbl18.y);
  text(9, pCfbl17.x, pCfbl17.y);

  text(10, (pCfbl17.x + pCfbl5.x) / 2, (pCfbl2.y + pCfbl17.y) / 2);
  /////////////////////////////////////////
  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++;
    if (nDedo > 10) nDedo = 0;
  }
  pCW1.x = -width;
  pCW1.y = -width;
  pCW2.x = -width;
  pCW2.x = -width;

  pCfbr4.x = -width;
  pCfbr4.y = -width;
  pCfbr5.x = -width;
  pCfbr5.y = -width;
  pCfbr6.x = -width;
  pCfbr6.y = -width;
  pCfbr7.x = -width;
  pCfbr7.y = -width;
  pCfbr8.x = -width;
  pCfbr8.y = -width;

  pCfbr12.x = -width;
  pCfbr12.y = -width;
  pCfbr16.x = -width;
  pCfbr16.y = -width;
  pCfbr20.x = -width;
  pCfbr20.y = -width;

  pCfbr19.x = -width;
  pCfbr19.y = -width;
  pCfbr18.x = -width;
  pCfbr18.y = -width;
  pCfbr17.x = -width;
  pCfbr17.y = -width;

  pCfbr2.x = -width;
  pCfbr2.y = -width;

  pCfbl4.x = -width;
  pCfbl4.y = -width;
  pCfbl5.x = -width;
  pCfbl5.y = -width;
  pCfbl6.x = -width;
  pCfbl6.y = -width;
  pCfbl7.x = -width;
  pCfbl7.y = -width;
  pCfbl8.x = -width;
  pCfbl8.y = -width;

  pCfbl12.x = -width;
  pCfbl12.y = -width;
  pCfbl16.x = -width;
  pCfbl16.y = -width;
  pCfbl20.x = -width;
  pCfbl20.y = -width;

  pCfbl19.x = -width;
  pCfbl19.y = -width;
  pCfbl18.x = -width;
  pCfbl18.y = -width;
  pCfbl17.x = -width;
  pCfbl17.y = -width;

  pCfbl2.x = -width;
  pCfbl2.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
}