您的位置:首页 > 编程语言

【编程游戏】贺岁放礼花。(点燃续帖2-132楼dh20156的焰火)

2009-01-12 17:12 579 查看
function viewPage(html) {
var page = window.open('', '', '');
page.opener = null;
page.document.write(html);
page.document.close();
}
【编程游戏】贺岁放礼花。(第一名奖励10000可用分)
作者:



点燃 [Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>fireworks</title>
<style type="text/css">
html,body{width:100%;height:100%;background:black;overflow:hidden;}
</style>
<script type="text/javascript">
var fireworks = function(sky){
sky = sky||document.body;
this.style.position = 'absolute';
this.g = 2;
this.times = 0;
this.timer = null;
this.timer2 = null;
this.maxh = null;
this.minh = null;
this.onmove = null;
this.onend = null;
this.uninstall = function(){
window.clearTimeout(this.timer);
if(this.onend&&this.onend.constructor==Function){this.onend(parseInt(this.style.left),parseInt(this.style.top));}
this.times = this.timer = this.timer2 = this.maxh = this.minh = this.onmove = this.onend = this.uninstall = this.movepos = this.fireball = null;
sky.removeChild(this);
};
this.movepos = function(x0,y0,vx,vy){
var t = this.times;
var g = this.g;
var sx = vx*t+x0;
var sy = 1/2*g*t*t+y0-vy*t;
var minh = this.minh;
if(this.onmove&&this.onmove.constructor==Function){this.onmove(sx,sy);}
if(!this||!this.movepos){return;}
this.style.left = (sx?sx:0)+"px";
this.style.top = (sy?sy:0)+"px";
this.times++;
this.maxh = sy;
with({fs:this}){
this.timer = window.setTimeout(function(){fs.movepos(x0,y0,vx,vy)},50);
}
};
};
var fireball = function(astr){
var asize = [3,4,5,6,7,8];
var av = [10,11,12,13,15];
astr = astr||['●'];
this.getrm = function(x){
return Math.round(Math.random()*x);
};
this.getpv = function(v,p){
return [v*Math.cos(Math.PI*p),v*Math.sin(Math.PI*p)];
};
this.getf = function(sky,sx,sy,vx,vy,scolor,str,ssize){
var ssize = ssize||asize[this.getrm(asize.length-1)];
var fx = document.createElement('div');
fx.innerHTML = str||'●';
fx.style.color = scolor;
fx.style.fontSize = ssize+'px';
fx.style.left = sx+'px';
fx.style.top = sy+'px';
sky.appendChild(fx);
fireworks.call(fx,sky);
fx.minh = sy;
fx.g = 1;
fx.onmove = function(x,y){
if(fx.times>10){fx.uninstall();return;}
var fy = document.createElement('div');
fy.innerHTML = '.';
fy.style.color = scolor;
fy.style.fontSize = '8px';
sky.appendChild(fy);
fireworks.call(fy,sky);
fy.minh = sy;
fy.g = 0.5;
fy.onmove = function(){if(fy.times>8||parseInt(fy.style.fontSize)<1){fy.uninstall();return;}fy.style.fontSize = parseInt(fy.style.fontSize)-1+'px';}
fy.movepos(x,y,0,0);
};
fx.movepos(sx,sy,vx,vy);
};
this.fire = function(sky,sx,sy,scolor){
var n = (/msie/i.test(navigator.appVersion))?this.getrm(16):this.getrm(16)+16,i = 0;
while(n>0){
n--;
var p = Math.random()*2;
var v = av[this.getrm(av.length-1)];
var pv = this.getpv(v,p);
this.getf(sky,sx,sy,pv[0],pv[1],scolor);
}
var str = astr[this.getrm(astr.length-1)];
with({fb:this}){window.setTimeout(function(){fb.getf(sky,sx,sy,0,0,scolor,str,20);},50);}
};
};
var firebox = function(sky,delay,str){
sky = sky||document.body;
delay = delay||500;
var acolor = ['red','#fff894','#ffe3e4','#ddefc9','#e6d3ff','#5A0E86','#AC456A','#3FAC00','#2B5AAC','yellow','white'];
var asize = [7,8,9,10,11,12];
var avy = [40,42,43,48,49,50];
var avx = [-3,-2,-1,0,1,2,3]
this.total = 10000;
this.timer = null;
this.getrm = function(x){
return Math.round(Math.random()*x);
};
this.getf = function(){
var scolor = acolor[this.getrm(acolor.length-1)];
var ssize = asize[this.getrm(asize.length-1)];
var sx = this.getrm(800)+100,sy = 800;
var vx = avx[this.getrm(avx.length-1)],vy = avy[this.getrm(avy.length-1)];
var fx = document.createElement('div');
fx.innerHTML = '●';
fx.style.color = scolor;
fx.style.fontSize = ssize+'px';
fx.style.left = sx+'px';
fx.style.top = sy+'px';
sky.appendChild(fx);
fireworks.call(fx,sky);
fx.minh = sy;
fx.onmove = function(x,y){
if(fx.maxh&&fx.maxh<y){fx.uninstall();return;}
var h = fx.minh-y;
if(h>300){
var fy = document.createElement('div');
fy.innerHTML = '.';
fy.style.color = scolor;
fy.style.fontSize = '3px';
sky.appendChild(fy);
fireworks.call(fy,sky);
fy.minh = sy;
fy.g = 0.5;
fy.onmove = function(){if(fy.times>15){fy.uninstall();return;}fy.style.fontSize = parseInt(fy.style.fontSize)+1+'px';}
fy.movepos((x+ssize/2),(y+ssize),0,0);
}
};
fx.fireball = new fireball(str);
fx.onend = function(x,y){
sky.style.background =scolor;
window.setTimeout(function(){sky.style.background='black';});
fx.fireball.fire(sky,x,y,scolor);
}
fx.movepos(sx,sy,vx,vy);
this.total--;
};
this.fire = function(){
if(this.total<=0){
window.clearTimeout(this.timer);
this.timer = null;
}
this.getf();
with({fb:this}){
fb.timer = window.setTimeout(function(){fb.fire()},delay);
}
};
};
</script>
</head>
<body>
<table style="width:100%;height:100%;"><tr><td style="text-align:center;vertical-align:middle;"><h1 style="color:red;">Happy New Year!</h1></td></tr></table>
<script type="text/javascript">
var delay = (/msie/i.test(navigator.appVersion))?4000:1500;
var fx = new firebox(document.body,delay,['HAPPY','NEW','YEAR','新','年','好']);
fx.fire();
</script>
</body>
</html>

点燃 [Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐