Lange Spieker: verschil tussen versies

Uit De FNM-wiki
Naar navigatie springen Naar zoeken springen
Geen bewerkingssamenvatting
Geen bewerkingssamenvatting
Regel 1: Regel 1:
<html>
<script>
<head>
   const canvas = document.getElementById("birdCanvas");
   <style>
  const ctx = canvas.getContext("2d");
    body, html {
 
      margin: 0;
  let birdX = -50;
      padding: 0;
  const birdY = 150;
      overflow: hidden;
  const speed = 2;
    }
 
    #birdCanvas {
  let isBirdActive = true;
      position: absolute;
 
      top: 0;
   function drawLangeSpieker(x, y) {
      left: 0;
    ctx.save();
      pointer-events: none;
    ctx.translate(x, y);
      z-index: -1;
    }
   </style>
</head>
<body>
  <canvas id="birdCanvas" width="2000" height="500"></canvas>


  <script>
    // Legs
     const canvas = document.getElementById("birdCanvas");
    ctx.strokeStyle = "#654321";
     const ctx = canvas.getContext("2d");
     ctx.lineWidth = 4;
    ctx.beginPath();
    ctx.moveTo(0, 0);
    ctx.lineTo(-10, 80);
    ctx.moveTo(0, 0);
    ctx.lineTo(10, 80);
     ctx.stroke();


     let birdX = -50;  
     // Body
     const birdY = 150;
    ctx.beginPath();
     const speed = 2;
     ctx.fillStyle = "#ffcc00";
     ctx.ellipse(0, -30, 30, 45, 0, 0, Math.PI * 2);
    ctx.fill();


     function drawLangeSpieker(x, y) {
     // Neck
      ctx.save();
    ctx.fillRect(-5, -90, 10, 30);
      ctx.translate(x, y);


      // Legs
    // Head
      ctx.strokeStyle = "#654321";
    ctx.beginPath();
      ctx.lineWidth = 4;
    ctx.arc(0, -100, 15, 0, Math.PI * 2);
      ctx.beginPath();
    ctx.fill();
      ctx.moveTo(0, 0);
      ctx.lineTo(-10, 80);
      ctx.moveTo(0, 0);
      ctx.lineTo(10, 80);
      ctx.stroke();


      // Body
    // Eye
      ctx.beginPath();
    ctx.beginPath();
      ctx.fillStyle = "#ffcc00";
    ctx.fillStyle = "#000";
      ctx.ellipse(0, -30, 30, 45, 0, 0, Math.PI * 2);
    ctx.arc(5, -105, 2.5, 0, Math.PI * 2);
      ctx.fill();
    ctx.fill();


      // Neck
    // Beak
      ctx.fillRect(-5, -90, 10, 30);
    ctx.beginPath();
    ctx.fillStyle = "#ff6600";
    ctx.moveTo(13, -105);
    ctx.lineTo(33, -100);
    ctx.lineTo(13, -95);
    ctx.closePath();
    ctx.fill();


      // Head
    // Wing
      ctx.beginPath();
    ctx.beginPath();
      ctx.arc(0, -100, 15, 0, Math.PI * 2);
    ctx.fillStyle = "#ffaa00";
      ctx.fill();
    ctx.ellipse(-15, -35, 12, 25, Math.PI / 6, 0, Math.PI * 2);
    ctx.fill();


      // Eye
    ctx.restore();
      ctx.beginPath();
  }
      ctx.fillStyle = "#000";
      ctx.arc(5, -105, 2.5, 0, Math.PI * 2);
      ctx.fill();


      // Beak
  function resetBirdAfterRandomDelay() {
      ctx.beginPath();
    isBirdActive = false;
      ctx.fillStyle = "#ff6600";
      ctx.moveTo(13, -105);
      ctx.lineTo(33, -100);
      ctx.lineTo(13, -95);
      ctx.closePath();
      ctx.fill();


      // Wing
    const delay = Math.random() * 4000 + 1000; // 1 to 5 seconds
      ctx.beginPath();
    setTimeout(() => {
       ctx.fillStyle = "#ffaa00";
      birdX = -50;
      ctx.ellipse(-15, -35, 12, 25, Math.PI / 6, 0, Math.PI * 2);
       isBirdActive = true;
      ctx.fill();
    }, delay);
  }


      ctx.restore();
  function animate() {
    }
    ctx.clearRect(0, 0, canvas.width, canvas.height);


     function animate() {
     if (isBirdActive) {
      ctx.clearRect(0, 0, canvas.width, canvas.height);
       drawLangeSpieker(birdX, birdY);
       drawLangeSpieker(birdX, birdY);
      birdX += speed;


      birdX += speed;
       if (birdX > canvas.width + 50) {
       if (birdX > canvas.width + 50) {
         birdX = -50;
         resetBirdAfterRandomDelay();
       }
       }
    }


      requestAnimationFrame(animate);
    requestAnimationFrame(animate);
    }
  }


    animate();
  animate();
  </script>
</script>
</body>
</html>

Versie van 31 jul 2025 20:26

<script>

 const canvas = document.getElementById("birdCanvas");
 const ctx = canvas.getContext("2d");
 let birdX = -50;
 const birdY = 150;
 const speed = 2;
 let isBirdActive = true;
 function drawLangeSpieker(x, y) {
   ctx.save();
   ctx.translate(x, y);
   // Legs
   ctx.strokeStyle = "#654321";
   ctx.lineWidth = 4;
   ctx.beginPath();
   ctx.moveTo(0, 0);
   ctx.lineTo(-10, 80);
   ctx.moveTo(0, 0);
   ctx.lineTo(10, 80);
   ctx.stroke();
   // Body
   ctx.beginPath();
   ctx.fillStyle = "#ffcc00";
   ctx.ellipse(0, -30, 30, 45, 0, 0, Math.PI * 2);
   ctx.fill();
   // Neck
   ctx.fillRect(-5, -90, 10, 30);
   // Head
   ctx.beginPath();
   ctx.arc(0, -100, 15, 0, Math.PI * 2);
   ctx.fill();
   // Eye
   ctx.beginPath();
   ctx.fillStyle = "#000";
   ctx.arc(5, -105, 2.5, 0, Math.PI * 2);
   ctx.fill();
   // Beak
   ctx.beginPath();
   ctx.fillStyle = "#ff6600";
   ctx.moveTo(13, -105);
   ctx.lineTo(33, -100);
   ctx.lineTo(13, -95);
   ctx.closePath();
   ctx.fill();
   // Wing
   ctx.beginPath();
   ctx.fillStyle = "#ffaa00";
   ctx.ellipse(-15, -35, 12, 25, Math.PI / 6, 0, Math.PI * 2);
   ctx.fill();
   ctx.restore();
 }
 function resetBirdAfterRandomDelay() {
   isBirdActive = false;
   const delay = Math.random() * 4000 + 1000; // 1 to 5 seconds
   setTimeout(() => {
     birdX = -50;
     isBirdActive = true;
   }, delay);
 }
 function animate() {
   ctx.clearRect(0, 0, canvas.width, canvas.height);
   if (isBirdActive) {
     drawLangeSpieker(birdX, birdY);
     birdX += speed;
     if (birdX > canvas.width + 50) {
       resetBirdAfterRandomDelay();
     }
   }
   requestAnimationFrame(animate);
 }
 animate();

</script>