介绍
小编给大家分享一下javascript如何实现超好看的3 d烟花特效,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获、下面让我们一起去了解一下吧!
本文实例为大家分享了超好看3 d烟花的具体代码,供大家参考,具体内容如下
& lt; ! doctype html> & lt; html> & lt; head> & lt; meta charset=皍tf-8"祝辞 & lt; title> 3 d烟花& lt;/title> & lt; style> html,身体{ ,保证金:0 px; ,宽度:100%; ,高度:100%; ,溢出:隐藏; ,背景:# 000; } #帆布{ ,宽度:100%; ,高度:100%; } & lt;/style> & lt;/head> & lt; body> & lt; canvas id=癱anvas"祝辞& lt;/canvas> & lt; script> function initVars () { ,π=Math.PI; ,ctx=canvas.getContext (“2 d"); ,canvas.width=canvas.clientWidth; ,canvas.height=canvas.clientHeight; ,残雪=canvas.width/2; ,cy=canvas.height/2; ,playerZ=-25; ,playerX=playerY=playerVX=playerVY=playerVZ=节=偏航=pitchV=yawV=0; ,规模=600; ,准备阶段=0;seedInterval=5, seedLife=100;重力=.02点; ,种子=new 数组(); ,sparkPics=new 数组(); ,s=癶ttps://cantelope.org/NYE/"; ,(i=1; i<=10 + + i) { ,sparkPic=new 图像(); ,sparkPic.src=https://www.yisu.com/zixun/s +“火花”+我+“中将”; sparkPics.push (sparkPic); } 火花=new Array (); pow1=new音频(s +“pow1.ogg”); pow2=new音频(s +“pow2.ogg”); pow3=new音频(s +“pow3.ogg”); pow4=new音频(s +“pow4.ogg”); ?0; } 函数rasterizePoint (x, y, z) { var p、d; x -=playerX; y -=playerY; z -=playerZ; p=Math.atan2 (x, z); d=Math.sqrt (x * x + z * z); x=sin (p-yaw) * d; z=Math.cos (p-yaw) * d; p=Math.atan2 (y, z); d=Math.sqrt (y * y + z * z); y=sin (p-pitch) * d; z=Math.cos (p-pitch) * d; var rx1=-1000, ry1=1, rx2=1000, ry2=1, rx3=0, ry3=0, rx4=x, z ry4=,加州大学=(ry4-ry3) * (rx2-rx1)——(rx4-rx3) * (ry2-ry1); 如果(uc)返回{x: 0, y: 0, d: 1}; var ua=((rx4-rx3) * (ry1-ry3)——(ry4-ry3) * (rx1-rx3))/加州大学; var乌兰巴托=((rx2-rx1) * (ry1-ry3)——(ry2-ry1) * (rx1-rx3))/加州大学; 如果(z) z=.000000001; 如果(ua> 0 ua <1乌兰巴托> 0乌兰巴托<1){ 返回{ x:残雪+ (rx1 + ua * (rx2-rx1)) *, y: cy + y/z *规模, d: Math.sqrt (x * x + y * y + z * z) }; 其他}{ 返回{ x:残雪+ (rx1 + ua * (rx2-rx1)) *, y: cy + y/z *规模, d: 1 }; } } 函数spawnSeed () { 种子=新对象(); seed.x=-50 + math . random () * 100; seed.y=25; seed.z=-50 + math . random () * 100; seed.vx=.1-Math.random () * 2; seed.vy=-1.5;//* (1 + math . random ()/2); seed.vz=.1-Math.random () * 2; seed.born=帧; seeds.push(种子); } 函数splode (x, y, z) { t=5 +方法(math . random () * 150); sparkV=1 + math . random () * 2.5; 类型=方法(math . random () * 3); 开关(类型){ 例0: pic1=方法(math . random () * 10); 打破; 案例1: pic1=方法(math . random () * 10); 做{pic2=方法(math . random () * 10);}(pic2==pic1); 打破; 案例2: pic1=方法(math . random () * 10); 做{pic2=方法(math . random () * 10);}(pic2==pic1); 做{pic3=方法(math . random () * 10);},(pic3==pic1 | | pic3==pic2); 打破; } (m=1; mjavascript如何实现超好看的3 d烟花特效