Franjas animadas

by sosegon

HTML

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Geometric Progression Stripes</title>
    <style>
        body {
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            background-color: white;
        }
        canvas {
            background-color: white;
        }
    </style>
</head>
<body>
    <canvas id="canvas"></canvas>
    <script>
        const canvas = document.getElementById("canvas");
        const ctx = canvas.getContext("2d");

        // Canvas size
        canvas.width = 800;
        canvas.height = 400;

        const numStripes = 10;  // Number of stripes
        const initialWidth = 100; // Initial width of the first stripe
        const height = 30; // Height of each stripe
        const spacing = 10; // Space between stripes
        const scaleFactor = 0.7; // Geometric progression factor
        const skewFactor = 10; // How much each stripe is skewed
        const animationSpeed = 0.02; // Speed of animation

        let progress = 0; // Animation progress (0 to 1)
        let direction = 1; // 1 for forward, -1 for reverse

        function drawStripes(progress) {
            ctx.clearRect(0, 0, canvas.width, canvas.height);
            ctx.save();
            ctx.translate(100, canvas.height / 2);

            for (let i = 0; i < numStripes; i++) {
                const width = initialWidth * Math.pow(scaleFactor, i);
                const xOffset = i * skewFactor;
                const yOffset = i * (height + spacing);
                const animOffset = progress * (canvas.width - 200); // Animation effect

                ctx.fillStyle = "black";
                ctx.beginPath();
                ctx.moveTo(animOffset + xOffset, yOffset);
                ctx.lineTo(animOffset + xOffset + width, yOffset);
                ctx.lineTo(animOffset + xOffset +...