initVariables();
xpDcha = 0;
ypDcha = 0;
xpIzda = 0;
ypIzda = 0;
rp = 50;
imgLoad = null;
loadFoto = servidorURL + "/assets/images/R1.png"

//imgLoad.hide();
unaVez = true;
nFoto = 0;
nRandom = 100;
numR = 0, numL = 0, numT = 0;
nLado = 0;

xpDcha = wsIni + wVideo - rp;
ypDcha = hsIni + rp * 2;
xpIzda = wsIni + rp;
ypIzda = hsIni + rp * 2;
////////////////////////////////////////////////////////
function funcionGo(ctx, width, height) {
  let nPorcentaje = 1;
  if (lInit) {
    lHandmano = true;
    if (!deviceAndroid) nPorcentaje = 1;
    else nPorcentaje = 2;
    jsreinitProcedure();
    lDelayLocal = true;
    lDelayLocalManual = false;
    txClocalUp = "La imagen es de la mano dcha. o izda.";
    txClocalDown = "";
    jsinitTimer(1);
    if (unaVez) {
      nLado = int(random(0, 100));
      nFoto = int(random(1, nRandom));
      if (nLado < 50) loadFoto = servidorURL + "/assets/images/L" + str(nFoto) + ".png";
      if (nLado > 49) loadFoto = servidorURL + "/assets/images/R" + str(nFoto) + ".png"
      imgLoad = loadImage(loadFoto);
      unaVez = false;
    }
    xpDcha = wsIni + wVideo - rp;
    ypDcha = hsIni + rp * 2;
    xpIzda = wsIni + rp;
    ypIzda = hsIni + rp * 2;
    numR = 0;
    numL = 0;
    numT = 0;
  }
  if (!imgLoad) imgLoad = loadImage(loadFoto);
  //displaymodulo(0);
  push();
  translate(wsIni + wVideo / 2, imgLoad.height / 2 - (imgLoad.width / imgLoad.height) * 184 / 2);
  rotate(frameCount * 0.01);
  image(imgLoad, -imgLoad.width / 2 + (imgLoad.width / imgLoad.height) * 184 / 2, -imgLoad.height / 2 + (imgLoad.width / imgLoad.height) * 184 / 2, imgLoad.width / nPorcentaje - (imgLoad.width / imgLoad.height) * 184, imgLoad.height / nPorcentaje - (imgLoad.width / imgLoad.height) * 184)
  pop();

  fill(255, 0, 0, 128);
  ellipse(xpDcha, ypDcha, rp * 2, rp * 2);
  ellipse(xpIzda, ypIzda, rp * 2, rp * 2);

  noStroke();
  fill(255);
  textSize(38);
  fill(0);
  text("izda.", xpIzda, ypIzda - 110);
  fill(255);
  fill(0, 0, 255, 26);
  circle(xpIzda, ypIzda, rp * 3);
  fill(0);
  text("dcha.", xpDcha, ypDcha - 110);
  fill(255);
  textSize(12);
  fill(0, 0, 255, 26);
  circle(xpDcha, ypDcha, rp * 3);

  fill(255);
  textSize(32);
  text(numT, width / 2, ypIzda + 15);
  text(numR, xpIzda, ypIzda + 15);
  text(numL, xpDcha, ypDcha + 15);
  //text("?", width / 2, height / 2);
  textSize(12);

  fill(255, 0, 0, 128);
  ellipse(pCW1.x, pCW1.y, rp * 2, rp * 2);
  ellipse(pCW2.x, pCW2.y, rp * 2, rp * 2);
  textSize(32);
  if (dist(xpDcha, ypDcha, pCW1.x, pCW1.y) < rp * 2 || dist(xpDcha, ypDcha, pCW2.x, pCW2.y) < rp * 2) {
    //if (nFoto < 50) {
    if (nLado < 50) {
      if (millis() - lapse > 100) {
        lapse = millis() + 1000;
        numL++;
        numT++;
        nFoto = int(random(1, nRandom));
        nLado = int(random(0, 100));
        if (nLado < 50) loadFoto = servidorURL + "/assets/images/L" + str(nFoto) + ".png";
        if (nLado > 49) loadFoto = servidorURL + "/assets/images/R" + str(nFoto) + ".png"
        imgLoad = loadImage(loadFoto);
        //console.info(nLado)
      }
    }
  }
  else {
    if (dist(xpIzda, ypIzda, pCW2.x, pCW2.y) < rp * 2 || dist(xpIzda, ypIzda, pCW1.x, pCW1.y) < rp * 2) {
      //if (nFoto > 35) {
      if (nLado > 49) {
        if (millis() - lapse > 100) {
          lapse = millis() + 1000;
          numR++;
          numT++;
          nFoto = int(random(1, nRandom));
          nLado = int(random(0, 100));
          if (nLado < 50) loadFoto = servidorURL + "/assets/images/L" + str(nFoto) + ".png";
          if (nLado > 49) loadFoto = servidorURL + "/assets/images/R" + str(nFoto) + ".png"
          imgLoad = loadImage(loadFoto);
          //console.info(nLado)
        }
      }
    }
  }
  pCW1.x = -width;
  pCW1.y = -width;
  pCW2.x = -width;
  pCW2.x = -width;
}
////////////////////////////////////////
