【编程游戏】贺岁放礼花。(点燃续帖2-133楼langtse的焰火)(修改自169楼Free_Wind22)时间:2022-04-09 08:46:35 【编程游戏】贺岁放礼花。(第一名奖励10000可用分) 作者: 点燃 [Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行] <!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" /> <meta http-equiv="description" content="新年许愿礼花V1.10版" /> <meta http-equiv="Author" content="Langtse"/> <title>【2009新年贺岁编程游戏】-- 点燃你的愿望礼花! - v1.10版</title> <style type="text/css"> *{overflow:hidden;} html, body{background:#000; height:100%; margin:0px; padding:0px;color:#FFF;} .ball{color:#FF0000; position:absolute; font-size:6px;} .star{color:#FF0000; position:absolute; font-size:12px;} </style> <script type="text/javascript"> ////////////////////////////////////////////////||||//////////////////////////////////////////////////////// //// 脚本代码区,请勿随意更改! //// function random(nMin,nMax) { return Math.round(Math.random()*(nMax-nMin)+nMin); } function filler(nMin,nMax) { this.result=""; this.amount=random(10,20); for(var iFill=0;iFill<this.amount;iFill++) { this.result+=String.fromCharCode(random(nMin,nMax)); } return this.result; } function Firework(sky, loop, wish){ this.index=0; this.wish=wish?wish:"新年快乐"; this.sky = sky; this.skyWidth = document.body.clientWidth || document.documentElement.clientWidth; this.skyHeight= document.body.clientHeight || document.documentElement.clientHeight; this.x = 0; this.y = 0; this.step = 20; this.delay = 30; this.stars = []; this.r = 10; this.step2 = 7; this.radius = random(60,180); this.angle = 45; this.num = this.wish.length; 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); }, show : function(){ var b = document.createElement("div"); b.innerHTML = "●"; b.className = "ball"; b.style.left = this.x + "px"; b.style.top = this.y + "px"; this.ball = b; this.sky.appendChild(this.ball); }, hide : function(){ this.sky.removeChild(this.ball); this.ball = null; }, hideStars : function(){ for(var i=0; i<this.num; i++){ this.sky.removeChild(this.stars[i]); this.stars[i] = null; } if(this.loop){ this.play(); } this.index++; }, setStarPos : function(){ for(var i=0; i<this.num; i++){ var p = parseInt(this.r / this.radius * 10); this.stars[i].style.left = this.x - parseInt(this.r * Math.sin(i * this.angle)) + "px"; this.stars[i].style.top = this.y - parseInt(this.r * Math.cos(i * this.angle)) + "px"; this.stars[i].style.fontSize = 6 + p + "px"; } }, showStars : function(){ if(this.index>this.wish.length-1){this.index=0;} var angles = [15, 30, 45, 60]; var maxs = [20, 12, 6, 10]; var colors = ['#FF0000','#00FF00','#0000FF','#FFFF00','#00FFFF']; var rand = random(0,maxs.length-1); this.r = 10; this.num = random(6,20); this.angle = angles[rand]; for(var i=0; i<this.num; i++){ this.stars[i] = document.createElement("div"); if(!this.stars[i]){break;} this.stars[i].innerHTML = this.wish.charAt(this.index); this.stars[i].className = "star"; this.stars[i].style.color = colors[random(0,colors.length-1)]; this.sky.appendChild(this.stars[i]); } }, 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; this.setStarPos(); setTimeout(function(){self.moveStars();}, this.delay); }else{ setTimeout(function(){self.hideStars();}, 300 * Math.random()); } }, fire : function(){ this.hide(); this.showStars(); this.moveStars(); }, move : 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 = 12 - p + "px"; this.ball.style.top = this.y + "px"; setTimeout(function(){self.move();}, this.delay); }else{ this.fire(); } }, play : function(){ this.init(); this.show(); this.move(); } }; window.onload = function() { var mywish; ////////////////////////////////////////////////||||//////////////////////////////////////////////////////// //// 新年许愿区,请许下你的愿望! //// mywish=["★☆◎◇¤※○@■△", "请投我一票吧","恭贺新春", "新年快乐", filler(19968,40869)]; ////////////////////////////////////////////////||||//////////////////////////////////////////////////////// //// 礼花燃放区,请注意安全! //// for(var iwish=0;iwish<random(1,mywish.length+1);iwish++) { new Firework(document.body, true, mywish[iwish]).play(); } }; </script> </head> <body> </body> </html> 点燃 [Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]