Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
1.7 kB
1
Indexable
Never
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <style>
    #soroban {
      display: flex;
      justify-content: center;
      margin-top: 50px;
    }

    .rod {
      display: flex;
      flex-direction: column;
      border: 1px solid #000;
      margin: 0 10px;
      padding: 10px;
    }

    .bead {
      width: 40px;
      height: 40px;
      background-color: #000;
      border-radius: 50%;
      margin: 5px 0;
      cursor: pointer;
    }
  </style>
</head>
<body>
  <div id="soroban"></div>

  <script>
    // Function to toggle bead state (up/down)
    function toggleBead(row, bead) {
      beads[row][bead] = 1 - beads[row][bead];
      renderSoroban();
    }

    // Function to render the soroban based on bead states
    function renderSoroban() {
      const sorobanElement = document.getElementById('soroban');
      sorobanElement.innerHTML = '';

      for (let i = 0; i < beads.length; i++) {
        const rodElement = document.createElement('div');
        rodElement.classList.add('rod');

        for (let j = 0; j < beads[i].length; j++) {
          const beadElement = document.createElement('div');
          beadElement.classList.add('bead');
          beadElement.style.backgroundColor = beads[i][j] ? '#fff' : '#000';
          beadElement.onclick = () => toggleBead(i, j);

          rodElement.appendChild(beadElement);
        }

        sorobanElement.appendChild(rodElement);
      }
    }

    // Initial state of the soroban (5 rods, 1 bead per rod initially down)
    const beads = Array.from({ length: 5 }, () => Array(1).fill(0));

    // Render initial soroban
    renderSoroban();
  </script>
</body>
</html>
Leave a Comment