【编程游戏】贺岁放礼花。(点燃175楼web_show的焰火)(修改自169楼Free_Wind22)...

<script type="text/javascript"> function viewPage(html) { var page = window.open('', '', ''); page.opener = null; page.document.write(html); page.document.close(); } </script> 【编程游戏】贺岁放礼花。(第一名奖励10000可用分)
作者: avatar
点燃[Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行] <iframe src="http://vote.csdn.net/VotePostSimple.aspx?voteid=814" marginheight="0" marginwidth="0" scrolling="no" width="100%" frameborder="0" height="400"></iframe> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>【编程游戏】贺岁放礼花 -- freewind</title> <style type="text/css"> html,body{background:#000; height:100%; margin:0px; padding:0px;color:#FFF;} .ball{color:#FF0000; position:absolute; font-size:16px;} .star{color:#FF0000; position:absolute; font-size:4px;} </style> <script type="text/javascript"> function Firework(sky, loop){ this.sky = sky; this.skyWidth = document.body.clientWidth || document.documentElement.clientWidth; this.skyHeight= document.body.clientHeight || document.documentElement.clientHeight; this.x = this.y = 0; this.step = 20; this.delay = 30; this.stars = []; this.r = 10; this.step2 = 7; this.radius = 90; this.angle = 45; this.num = 16; this.loop = loop; } Firework.prototype = { init : function(){ this.x = parseInt(this.skyWidth/2 * Math.random()) + this.skyWidth / 4; this.y = this.skyHeight; this._y = parseInt((this.skyHeight / 4) * Math.random()) + this.skyHeight / 5; }, showBall : function(){ this.ball = document.createElement("div"); this.ball.innerHTML = "●"; this.ball.className = "ball"; this.ball.style.left = this.x + "px"; this.ball.style.top = this.y + "px"; this.sky.appendChild(this.ball); }, moveBall : function(){ var self = this; if(this.y > this._y){ var p = parseInt((this.skyHeight - this.y) / (this.skyHeight - this._y)*10); this.y -= (this.step - p * 1.6); this.ball.style.fontSize = 16 - p + "px"; this.ball.style.top = this.y + "px"; setTimeout(function(){self.moveBall();}, this.delay); }else{ this.fire(); } }, hideBall : function(){ this.sky.removeChild(this.ball); this.ball = null; }, showStars : function(){ var colors = ['#FF0000','#FF00FF','#00FF00','#00FFFF','#FFFF00','#FF0000','#FF00FF','#00FF00','#00FFFF','#FFFF00']; //添加处 var starsBox = ['★','☆','∵','∴','*','+','#']; var n = cs = parseInt(Math.random() * colors.length / 2); var cc = parseInt(Math.random() * colors.length / 2); var colorMode = parseInt(Math.random() * 2); this.r = 10; this.radius = Math.round(Math.random() * 30) + 60; this.num = Math.round(Math.random() * 6 + 4) * 2; this.angle = 180 / this.num * 2; for(var i=1; i<=this.num; i++){ this.stars[i] = document.createElement("div"); //修改处 this.stars[i].innerHTML = starsBox[parseInt(Math.random() * starsBox.length / 2)]; this.stars[i].className = "star"; if(colorMode == 1){ this.stars[i].style.color = colors[n]; if(++n > cs + cc) n = cs; }else{ this.stars[i].style.color = colors[parseInt(Math.random() * colors.length)]; } this.sky.appendChild(this.stars[i]); } }, //添加处 fRandom : function(s,e){ var iRan, iMax, iMin, iRtn; s = parseInt(s); e = parseInt(e); iRan = Math.random(); if(!isNaN(e)){ iMax = Math.max(s,e); iMin = Math.min(s,e); iRtn = Math.ceil(iRan * (iMax - iMin) + iMin); if (iRtn >= e) iRtn = iRtn - 1; return iRtn; } if(!isNaN(s)){ iRtn = Math.ceil(iRan * s); if (iRtn >= s) iRtn = iRtn - 1; return iRtn; } return 0; }, moveStars : function(){ var self = this; if(this.r < this.radius){ var p = this.step2 - parseInt(this.r / this.radius * 5); p = p < 1 ? 1 : p; this.r += p; p = parseInt(this.r / this.radius * 100); for(var i=1; i<=this.num; i++){ //修改处 this.stars[i].style.left = self.fRandom(this.x-80,this.x+80)+"px"; this.stars[i].style.top = self.fRandom(this.y-80,this.y+80)+"px"; //this.stars[i].style.left = this.x - Math.round(this.r * Math.sin(Math.PI - (Math.PI / 180 * this.angle * i))) + "px"; //this.stars[i].style.top = this.y - Math.round(this.r * Math.cos(Math.PI - (Math.PI / 180 * this.angle * i))) + "px"; this.stars[i].style.fontSize = 4 + p/10 + "px"; if(p > 85){ var opacity = 100 - (p - 85) * 4; if(document.all){ this.stars[i].style.filter = "alpha(opacity=" + opacity + ")"; }else{ this.stars[i].style.MozOpacity = opacity / 100; } } } setTimeout(function(){self.moveStars();}, this.delay); }else{ setTimeout(function(){self.hideStars();}, 300 * Math.random()); } }, hideStars : function(){ for(var i=1; i<=this.num; i++){ this.sky.removeChild(this.stars[i]); this.stars[i] = null; } if(this.loop){ this.play(); } }, fire : function(){ this.hideBall(); this.showStars(); this.moveStars(); }, play : function(){ this.init(); this.showBall(); this.moveBall(); } }; window.onload = function(){ for(var i=0; i<5; i++) new Firework(document.body, true).play(); }; </script> </head> <body> </body> </html>
点燃[Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值