• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com专业计算机教程网站
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • html/xhtml
  • html5
  • CSS
  • XML/XSLT
  • Dreamweaver教程
  • Frontpage教程
  • 心得技巧
  • bootstrap
  • vue
  • AngularJS
  • HBuilder教程
  • css3
  • 浏览器兼容
  • div/css
  • 网页编辑器
  • axure
您的位置:首页 > 网页设计 >html5 > 用HTML5制作烟火效果的教程_html5教程技巧

用HTML5制作烟火效果的教程_html5教程技巧

作者:匿名 字体:[增加 减小] 来源:互联网 时间:2018-12-03

本文主要包含HTML5等相关知识,匿名希望在学习及工作中可以帮助到您
要过年了,过年想到的就是放烟火啦。。。。于是就用canvas写了个放烟火的效果,鼠标点击也会产生烟火,不过不要产生太多烟火哦,一个烟火散出的粒子是30到200个之间,当页面上的粒子数量达到一定的时候,页面就会很卡咯,我也没特意去优化神马的。以后有空再说吧。

  直接上DEMO吧:放烟火

  原理很简单。。。就写一个烟火类以及碎屑类,实例化后让它飞起来,然后到达某个点后,把这个烟火对象的dead属性置为true,然后再实例化出一定数量的碎屑对象,并且给与碎屑对象随机一个要到达的目标点,然后让所有碎屑对象飞过去就行了。

  【烟火】

  1. var Boom = function(x,r,c,boomArea,shape){ //烟火对象
  2. this.booms = [];
  3. this.x = x;
  4. this.y = (canvas.height+r);
  5. this.r = r;
  6. this.c = c;
  7. this.shape = shape || false;
  8. this.boomArea = boomArea;
  9. this.theta = 0;
  10. this.dead = false;
  11. this.ba = parseInt(getRandom(80 , 200));
  12. }
  13. Boom.prototype = {
  14. _paint:function(){
  15. ctx.save();
  16. ctx.beginPath();
  17. ctx.arc(this.x,this.y,this.r,0,2*Math.PI);
  18. ctx.fillStyle = this.c;
  19. ctx.fill();
  20. ctx.restore();
  21. },
  22. _move:function(){
  23. var dx = this.boomArea.x - this.x , dy = this.boomArea.y - this.y;
  24. thisthis.x = this.x+dx*0.01;
  25. thisthis.y = this.y+dy*0.01;
  26. if(Math.abs(dx)<=this.ba && Math.abs(dy)<=this.ba){
  27. if(this.shape){
  28. this._shapBoom();
  29. }
  30. else this._boom();
  31. this.dead = true;
  32. }
  33. else {
  34. this._paint();
  35. }
  36. },
  37. _drawLight:function(){
  38. ctx.save();
  39. ctx.fillStyle = "rgba(255,228,150,0.3)";
  40. ctx.beginPath();
  41. ctx.arc(this.x , this.y , this.r+3*Math.random()+1 , 0 , 2*Math.PI);
  42. ctx.fill();
  43. ctx.restore();
  44. },
  45. _boom:function(){ //普通爆炸
  46. var fragNum = getRandom(30 , 200);
  47. var style = getRandom(0,10)>=5? 1 : 2;
  48. var color;
  49. if(style===1){
  50. color = {
  51. a:parseInt(getRandom(128,255)),
  52. b:parseInt(getRandom(128,255)),
  53. c:parseInt(getRandom(128,255))
  54. }
  55. }
  56. var fanwei = parseInt(getRandom(300, 400));
  57. for(var i=0;i<fragNum;i++){
  58. if(style===2){
  59. color = {
  60. a:parseInt(getRandom(128,255)),
  61. b:parseInt(getRandom(128,255)),
  62. c:parseInt(getRandom(128,255))
  63. }
  64. }
  65. var a = getRandom(-Math.PI, Math.PI);
  66. var x = getRandom(0, fanwei) * Math.cos(a) + this.x;
  67. var y = getRandom(0, fanwei) * Math.sin(a) + this.y;

您可能想查找下面的文章:

相关文章

  • 2017-08-06HTML5 Canvas实现平移/放缩/旋转deom示例(附截图)
  • 2018-12-03Web 前端的未来会怎样?
  • 2018-12-037 个让人惊叹的 HTML5 鼠标动画图文详解
  • 2018-12-03基于HTML5 Canvas实现的3D动态Chart图表
  • 2018-12-03HTML5新增的Css选择器、伪类介绍_html5教程技巧
  • 2018-12-03移动端视网膜(Retina)屏幕下如何解决网页中1px显示问题?
  • 2018-12-03弹性盒模型 flex box的认知与使用
  • 2018-12-03canvas可以替代html与css了吗?
  • 2018-12-03详解HTML5中的WebSocket及实例代码
  • 2017-08-06用HTML5制作视频拼图的教程

文章分类

  • html/xhtml
  • html5
  • CSS
  • XML/XSLT
  • Dreamweaver教程
  • Frontpage教程
  • 心得技巧
  • bootstrap
  • vue
  • AngularJS
  • HBuilder教程
  • css3
  • 浏览器兼容
  • div/css
  • 网页编辑器
  • axure

最近更新的内容

    • 基于HTML5 的人脸识别技术
    • HTML5新增的Css选择器、伪类介绍_html5教程技巧
    • ngAnimate插件是做什么的?
    • HTML5如何为形状图上颜色怎么绘制具有颜色和透明度的矩形_html5教程技巧
    • 如何实现table表格中的斜线表头效果
    • 畅谈HTML5 到底是什么?
    • h5 Canvas中Fill 与Stroke文字效果实现实例
    • 原生js 有没有 手机移动端 滑动 的事件?
    • html5 Canvas画图教程(11)—使用lineTo/arc/bezierCurveTo画椭圆形
    • xhtml和html有什么区别?

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有