我改的[放烟火],哈哈

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
  2. <html xmlns="http://www.w3.org/1999/xhtml"
  3. <head> 
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
  5. <title>【编程游戏】贺岁放礼花 -- freewind</title> 
  6. <style type="text/css"
  7.     html, body{background:#000; height:100%; margin:0px; padding:0px;color:#FFF;} 
  8.     .ball{color:#FF0000; position:absolute; font-size:16px;} 
  9.     .star{color:#FF0000; position:absolute; font-size:4px;} 
  10. </style> 
  11. <script type="text/javascript"
  12. function Firework(sky, loop){ 
  13.     this.sky = sky; 
  14.     this.skyWidth = document.body.clientWidth || document.documentElement.clientWidth; 
  15.     this.skyHeight= document.body.clientHeight || document.documentElement.clientHeight; 
  16.     this.x = this.y = 0; 
  17.     this.step = 20; 
  18.     this.delay = 30; 
  19.     this.stars = []; 
  20.     this.r = 10; 
  21.     this.step2 = 7; 
  22.     this.radius = 80; 
  23.     this.angle = 45; 
  24.     this.num = 16; 
  25.     this.loop = loop; 
  26. Firework.prototype = { 
  27.     init : function(){ 
  28.         this.x = parseInt(this.skyWidth/2 * Math.random()) + this.skyWidth / 4; 
  29.         this.y = this.skyHeight; 
  30.         this._y = parseInt((this.skyHeight / 4) * Math.random()) + this.skyHeight / 5; 
  31.     }, 
  32.     show : function(){ 
  33.         var b = document.createElement("div"); 
  34.         b.innerHTML = "!"
  35.         b.className = "ball"
  36.         b.style.left = this.x + "px"
  37.         b.style.top = this.y + "px"
  38.         this.ball = b; 
  39.         this.sky.appendChild(this.ball); 
  40.     }, 
  41.     hide : function(){ 
  42.         this.sky.removeChild(this.ball); 
  43.         this.ball = null
  44.     }, 
  45.     hideStars : function(){ 
  46.         for(var i=1; i<=this.num; i++){ 
  47.             this.sky.removeChild(this.stars[i]); 
  48.             this.stars[i] = null
  49.         } 
  50.         if(this.loop){ 
  51.             this.play(); 
  52.         } 
  53.     }, 
  54.     setStarPos : function(){ 
  55.         for(var i=1; i<=this.num; i++){ 
  56.             var p = parseInt(this.r / this.radius * 10); 
  57.             this.stars[i].style.left = this.x - parseInt(this.r * Math.sin(i * this.angle)) + "px"
  58.             this.stars[i].style.top = this.y - parseInt(this.r * Math.cos(i * this.angle)) + "px"
  59.             this.stars[i].style.fontSize = (18 * Math.random()) + "px"
  60.         } 
  61.     }, 
  62.     showStars : function(){ 
  63.         var angles = [15, 30, 45, 60]; 
  64.         var maxs = [20, 12, 6, 10]; 
  65.         var colors = ['#FF0000','#FF00FF','#00FF00','#00FFFF','#FFFFF0']; 
  66.         var rand = parseInt(Math.random() * maxs.length); 
  67.         this.r = 10; 
  68.         this.num = maxs[rand]; 
  69.         this.angle = angles[rand]; 
  70.         for(var i=1; i<=this.num; i++){ 
  71.             this.stars[i] = document.createElement("div"); 
  72.             this.stars[i].innerHTML = "*"
  73.             this.stars[i].className = "star"
  74.             this.stars[i].style.color = colors[parseInt(Math.random()*colors.length)]; 
  75.             this.sky.appendChild(this.stars[i]); 
  76.         } 
  77.     }, 
  78.     moveStars : function(){ 
  79.         var self = this
  80.         if(this.r < this.radius){ 
  81.             var p = this.step2 - parseInt(this.r / this.radius * 5); 
  82.             pp = p < 1 ? 1 : p; 
  83.             this.r += p; 
  84.             this.setStarPos(); 
  85.             setTimeout(function(){self.moveStars();}, this.delay); 
  86.         }else
  87.             setTimeout(function(){self.hideStars();}, 300 * Math.random()); 
  88.         } 
  89.     }, 
  90.     fire : function(){ 
  91.         this.hide(); 
  92.         this.showStars(); 
  93.         this.moveStars(); 
  94.     }, 
  95.     move : function(){ 
  96.         var self = this
  97.         if(this.y > this._y){ 
  98.             var p = parseInt((this.skyHeight - this.y) / (this.skyHeight - this._y)*10); 
  99.             this.y -= (this.step - p * 1.6); 
  100.             this.ball.style.fontSize = 16 - p + "px"
  101.             this.ball.style.top = this.y + "px"
  102.             setTimeout(function(){self.move();}, this.delay); 
  103.         }else
  104.             this.fire(); 
  105.         } 
  106.     }, 
  107.     play : function(){ 
  108.         this.init(); 
  109.         this.show(); 
  110.         this.move(); 
  111.     } 
  112. }; 
  113. function ToFire(){ 
  114.     for(var i=0;i<parseInt(Math.random()*3)+3;i++){ 
  115.         new Firework(document.body, false).play(); 
  116.     } 
  117. }; 
  118. window.onload=ToFire; 
  119. window.document.onclick= ToFire;</script> 
  120. </head> 
  121. <body> 
  122. 用你的鼠标再次点燃烟火吧~(Click To Fire) 
  123. </body> 
  124. </html> 


放烟火(修改自:http://blog.youkuaiyun.com/zswang/archive/2008/12/26/3616736.aspx

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值