canvas实现粒子向上发射器动画效果代码
代码语言:html
所属分类:粒子
代码描述:canvas实现粒子向上发射器动画效果代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <style> body, html { margin: 0; padding: 0; overflow: hidden; background-color: #111; } canvas { display: block; } </style> </head> <body translate="no"> <canvas id="embersCanvas"></canvas> <script > const canvas = document.getElementById('embersCanvas'); const ctx = canvas.getContext('2d'); canvas.width = window.innerWidth; canvas.height = window.innerHeight; const embers = []; const emberCount = 200; // Ember particle settings const emberSettings = { maxSize: 4, minSize: 1, maxSpeed: 7, minSpeed: 0.5, color: 'rgba(255, 69, 0, 0.7)' // Orange-red color with transparency }; // Adjust canvas size on resize window.addEventListener('resize', () => { canvas.width = window.innerWidth; canvas.height = window.innerHeight; }); // Ember particle class class Ember { constructor() { this.reset(); } reset() { this.x = Math.random(.........完整代码请登录后点击上方下载按钮下载查看
网友评论0