Показать сообщение отдельно
  #4 (permalink)  
Старый 29.05.2021, 18:30
Аватар для рони
Профессор
Отправить личное сообщение для рони Посмотреть профиль Найти все сообщения от рони
 
Регистрация: 27.05.2010
Сообщений: 33,134

canvas wave волна
Katy93,
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>HTML 5 Canvas</title>
    <style type="text/css">
        html,
        body {
            margin: 0px;
        }
        canvas {
            display: block;
            position: absolute;
            top: 0px;
            left: 0px;
        }
    </style>
</head>
<body>
    <canvas id="canvas">
        Your browser does not support HTML5 canvas. If you would
        like to view, please update your browser.
    </canvas>
    <script>
        Rectangle = function(x, y, w, h) {
            this.x = x;
            this.y = y;
            this.yy = y;
            this.width = w;
            this.height = h;
            this.to = [205, 15];
            this.draw = function(ctx) {
                ctx.fillStyle = "#000";
                ctx.fillRect(this.x, this.y, this.width, this.height);
            }
        }
        var canvas = document.getElementById("canvas");
        canvas.width = window.innerWidth;
        canvas.height = window.innerHeight;
        var context = canvas.getContext("2d");
        function anim(a) {
            function e(b) {
                context.clearRect(a.x, a.y, a.width, a.height)
                var k = .03;
                a.yy += (a.to[0] - a.yy) * k;
                a.y = Math.trunc(a.yy)
                a.draw(context);
                if (Math.abs(a.yy - a.to[0]) < .5) {
                    a.to.reverse();
                    anim(a)
                } else requestAnimationFrame(e)
            }
            requestAnimationFrame(e)
        }
        for (var i = 0; i < 10; i++) {
            var rect = new Rectangle(15 + i * 52, 45 + (Math.cos(i) * 70 | 0), 50, 40)
            anim(rect)
        }
    </script>
</body>
</html>

Последний раз редактировалось рони, 29.05.2021 в 18:33.
Ответить с цитированием