js实现canvas大火燃烧火焰动画效果代码

代码语言:html

所属分类:动画

代码描述:js实现canvas大火燃烧火焰动画效果代码

代码标签: 大火 燃烧 火焰 动画 效果

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<html>
<head>
    <style>
        body {
            background: #000;
            height: 100vh;
            overflow: hidden;
        }

        canvas {
            -webkit-animation: fade-in 2000ms 1000ms forwards;
            animation: fade-in 2000ms 1000ms forwards;
            background: #000;
            background: radial-gradient(circle at 50% 75%, #311, #000);
            border-radius: 50%;
            bottom: 0;
            box-shadow: inset 0 0 0 10px rgba(255, 255, 255, 0.05);
            left: 0;
            margin: auto;
            opacity: 0;
            position: absolute;
            right: 0;
            top: 0;
        }

@-webkit-keyframes fade-in {
            to {
                opacity: 1;
            }
        }

@keyframes fade-in {
            to {
                opacity: 1;
            }
        }
        .static {
            -webkit-animation: fade-in2 2000ms 1000ms forwards;
            animation: fade-in2 2000ms 1000ms forwards;
            border-radius: 50%;
            bottom: 0;
            height: 400px;
            margin: auto;
            left: 0;
            opacity: 0;
            position: absolute;
            right: 0;
            top: 0;
            width: 400px;
        }

@-webkit-keyframes fade-in2 {
            to {
                opacity: 0.06;
            }
        }

@keyframes fade-in2 {
            to {
                opacity: 0.06;
            }
        }
    </style>

</head>
<bod>
    <canvas width="400" height="400"></canvas>
    <div class="static"></div>
    <script>
        console.clear();

        let $ = {};

        /*
                       |=|ˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉ/
            [::{}{}{}{}|=| UTILITY
                       |=|________________________________/
            */

        $.PI = Math.PI;
        $.TAU = $.PI * 2;

        $.rand = (min, max) => {
            return Math.random() * (max - min) + min;
        };

        $.hsla = (h, s, l, a) => {
            return `hsla(${h}, ${s}%, ${l}%, ${a})`;
        };

        $.baseRange = (base, range) => {
            return base + $.rand(-range, range);
        };

        /*
              |=|ˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉ/
   [::{}{}{}{}|=| POOL
              |=|________________________________/
   */

        $.Pool = class {
            constructor(base, preallocateAmount) {
                this.base = base;
                this.preallocateAmount = preallocateAmount || 0;
                this.alive = [];
                this.dead = [];
                this.length = 0;
                this.deadLength = 0;
                if (this.preallocateAmount) {
                    this.preallocate();
                }
            }
            preallocate() {
                for (var i = 0; i < this.preallocateAmount; i++) {
                    this.dead.push(new this.base());
                    this.deadLength++;
                }
            }
            create(opt) {
                if (this.deadLength) {
                    var obj = this.dead.pop();
                    obj.init(opt);
   .........完整代码请登录后点击上方下载按钮下载查看

网友评论0