I need to build an offline app for the desktop. Any help or better step by step instructions guide for Wappler would be awesome, please!

Hey @Ayhan_Khan Welcome to the Wappler community. Last year, I was tasked with creating a website for a pizzeria, and I recall experimenting with a fun idea designing a pizza with slices resembling buttons. The most effective way to achieve this is by using canvas. I’ve provided a sample and accompanying code for you to try out and explore. Best of luck with your first application using Wappler!

<!DOCTYPE html>
<html lang="es">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <style>
    body {
      display: flex;
      justify-content: center;
      align-items: center;
      height: 100vh;
      margin: 0;
    }

    canvas {
      border: 1px solid #000;
    }
  </style>
</head>
<body>
  <canvas id="pizzaCanvas" width="400" height="400"></canvas>

  <script>
    const canvas = document.getElementById('pizzaCanvas');
    const ctx = canvas.getContext('2d');
    const centerX = canvas.width / 2;
    const centerY = canvas.height / 2;
    const radius = 150;
    const numSlices = 8;
    const sliceAngle = (2 * Math.PI) / numSlices;

    const sliceStates = new Array(numSlices).fill(false);

    function drawSlice(startAngle, endAngle, color, index) {
      ctx.beginPath();
      ctx.moveTo(centerX, centerY);
      ctx.arc(centerX, centerY, radius, startAngle, endAngle);
      ctx.fillStyle = color;
      ctx.fill();
      ctx.stroke();
      ctx.closePath();
    }

    function handleSliceClick(event) {
      const rect = canvas.getBoundingClientRect();
      const x = event.clientX - rect.left - centerX;
      const y = event.clientY - rect.top - centerY;

      const angle = (Math.atan2(y, x) + 2 * Math.PI) % (2 * Math.PI);
      const sliceIndex = Math.floor(angle / sliceAngle);

      sliceStates[sliceIndex] = !sliceStates[sliceIndex];

      const sliceColor = sliceStates[sliceIndex] ? '#593C8F' : (sliceIndex % 2 === 0 ? '#ffcc00' : '#cc6600');

      drawSlice(sliceIndex * sliceAngle, (sliceIndex + 1) * sliceAngle, sliceColor, sliceIndex);
    }

    function drawPizza() {
      for (let i = 0; i < numSlices; i++) {
        const startAngle = i * sliceAngle;
        const endAngle = (i + 1) * sliceAngle;
        const sliceColor = sliceStates[i] ? '#593C8F' : (i % 2 === 0 ? '#ffcc00' : '#cc6600');

        drawSlice(startAngle, endAngle, sliceColor, i);
      }
    }

    canvas.addEventListener('click', handleSliceClick);

    drawPizza();
  </script>
</body>
</html>
4 Likes