<script type="text/javascript"> function viewPage(html) { var page = window.open('', '', ''); page.opener = null; page.document.write(html); page.document.close(); } </script>
【编程游戏】贺岁放礼花。(第一名奖励10000可用分)
作者:
点燃[Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行] <iframe src="http://vote.csdn.net/VotePostSimple.aspx?voteid=927" marginheight="0" marginwidth="0" scrolling="no" width="100%" frameborder="0" height="400"></iframe> <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.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.maxh = this.minh = this.onmove = this.onend = this.uninstall = this.movepos = 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(){ var asize = [3,4,5,6,7,8]; var av = [10,11,12,13,15]; 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){ var ssize = asize[this.getrm(asize.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.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 = 1; 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 = this.getrm(16)+16,i=0; while(n>0){ 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); n--; } }; }; var firebox = function(sky,delay){ 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.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(); fx.onend = function(x,y){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}){ this.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))?3500:1500; var fx = new firebox(document.body,delay); fx.fire(); </script> </body> </html>
点燃[Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]
作者:
![](http://avatar.profile.csdn.net/8/A/A/1_dh20156.jpg)
点燃[Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行] <iframe src="http://vote.csdn.net/VotePostSimple.aspx?voteid=927" marginheight="0" marginwidth="0" scrolling="no" width="100%" frameborder="0" height="400"></iframe> <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.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.maxh = this.minh = this.onmove = this.onend = this.uninstall = this.movepos = 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(){ var asize = [3,4,5,6,7,8]; var av = [10,11,12,13,15]; 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){ var ssize = asize[this.getrm(asize.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.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 = 1; 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 = this.getrm(16)+16,i=0; while(n>0){ 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); n--; } }; }; var firebox = function(sky,delay){ 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.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(); fx.onend = function(x,y){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}){ this.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))?3500:1500; var fx = new firebox(document.body,delay); fx.fire(); </script> </body> </html>
点燃[Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]