canvas粒子球体内烟花碰撞爆炸动画效果代码
代码语言:html
所属分类:粒子
代码描述:canvas粒子球体内烟花碰撞爆炸动画效果代码
代码标签: canvas 粒子 球体 烟花 碰撞 爆炸 动画
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <style> html, body { width: 100%; height: 100%; margin: 0; padding: 0; overflow: hidden; } .container { position: relative; width: 100%; height: 100%; margin: 0; padding: 0; background-color: #000000; } .container>canvas { position: absolute; top: 0; left: 0; } @import url('https://fonts.googleapis.com/css2?family=Pacifico&display=swap'); .title { font-family: 'Pacifico', cursive; color: #fff; text-shadow: 6px 4px #735b13; position: fixed; color: white; font-size: 40pt; z-index: 1; top: 45%; left: 40%; text-align: center; display: none; } .count { font-family: 'Pacifico', cursive; color: #fff; text-shadow: 6px 4px #735b13; position: fixed; color: white; font-size: 100pt; z-index: 1; top: 40%; left: 48%; text-align: center; } </style> </head> <body> <!-- From CyberSoft with Love !!! --> <span class="count">5</span> <span class="title">Happy New Year <br /> 2023</span> <div id="jsi-sphere-container" class="container"> </div> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/jquery-3.2.1.min.js"></script> <script> let i = 6; let timeOut = setInterval(() => { i--; document.querySelector(".count").innerHTML = i; if (i == 0) { clearInterval(timeOut); document.querySelector(".title").style.display = 'block'; document.querySelector(".count").style.display = 'none'; } }, 1000); var RENDERER = { AUXILIARY_LINE_COUMT: 16, MAX_ROTATION_ANGLE: Math.PI / 200, FIREWORK_INTERVAL: { min: 30, max: 100 }, init: function () { this.setParameters(); this.setupData(); this.reconstructMethod(); this.bindEvent(); this.render(); }, setParameters: function () { this.$document = $(document); this.$window = $(window); this.$container = $("#jsi-sphere-container"); this.width = this.$container.width(); this.height = this.$container.height(); this.contextBackground = $("<canvas />") .attr({ width: this.width, height: this.height }) .appendTo(this.$container) .get(0) .getContext("2d"); this.contextForeground = $("<canvas />") .attr({ width: this.width, height: this.height }) .appendTo(this.$container) .get(0) .getContext("2d"); this.camera = CAMERA.init(this); this.angleX = this.MAX_ROTATION_ANGLE / 2; this.angleY = this.MAX_ROTATION_ANGLE / 2; this.points = []; this.fireworks = []; this.maxFireworkInterval = this.getRandomValue(this.FIREWORK_INTERVAL) | 0; this.fireworkInterval = this.maxFireworkInterval; this.base = Math.min(this.width, this.height); this.scatterRadius = (this.base * 3) / 2; }, reconstructMethod: function () { this.render = this.render.bind(this); this.changeDepth = this.changeDepth.bind(this); this.changeAngle = this.changeAngle.bind(this); }, getRandomValue: function (range) { return range.min + (range.max - range.min) * Math.random(); }, bindEvent: function () { this.$document.on( "onwheel" in document ? "wheel" : "onmousewheel" in document ? "mousewheel" : "DOMMouseScroll", this.changeDepth ); this.$container.on("mousemove", this.changeAngle); }, setupData: function () { for (var i = 1; i < this.AUXILIARY_LINE_COUMT; i++) { for ( var phi = 0, deltaPhi = (Math.PI * 2) / (this.AUXILIARY_LINE_COUMT * 2 - Math.abs(this.AUXILIARY_LINE_COUMT * 2 - i * 4)); phi < Math.PI * 2; phi += deltaPhi ) { this.points.push( new POINT( this.camera, this.getAxis3D((Math.PI / this.AUXILIARY_LINE_COUMT) * i, phi) ) ); } } }, changeDepth: function (event) { event.preventDefault(); this.camera.move( 0, 0, (event.originalEvent.deltaY || -event.originalEvent.wheelDelta || event.originalEvent.detail) >= 0 ? 3 : -2 ).........完整代码请登录后点击上方下载按钮下载查看
网友评论0