|
一个Javascript烟花程序(改编) |
|
<html>
<head> <title>Fireworks</title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> </head> <body bgcolor="#000000"> <layer name="a0" left=10 top=10 visibility=show bgcolor="#ffffff" clip="0,0,2,2"></layer> <layer name="a1" left=10 top=10 visibility=show bgcolor="#fff000" clip="0,0,2,2"></layer> <layer name="a2" left=10 top=10 visibility=show bgcolor="#ffa000" clip="0,0,2,2"></layer> <layer name="a3" left=10 top=10 visibility=show bgcolor="#ff00ff" clip="0,0,2,2"></layer> <layer name="a4" left=10 top=10 visibility=show bgcolor="#00ff00" clip="0,0,2,2"></layer> <layer name="a5" left=10 top=10 visibility=show bgcolor="#ff00ff" clip="0,0,2,2"></layer> <layer name="a6" left=10 top=10 visibility=show bgcolor="#ff0000" clip="0,0,2,2"></layer> <layer name="a7" left=10 top=10 visibility=show bgcolor="#ffffff" clip="0,0,2,2"></layer> <layer name="a8" left=10 top=10 visibility=show bgcolor="#fff000" clip="0,0,2,2"></layer> <layer name="a9" left=10 top=10 visibility=show bgcolor="#ffa000" clip="0,0,2,2"></layer> <layer name="a10" left=10 top=10 visibility=show bgcolor="#ff00ff" clip="0,0,2,2"></layer> <layer name="a11" left=10 top=10 visibility=show bgcolor="#00ff00" clip="0,0,2,2"></layer> <layer name="a12" left=10 top=10 visibility=show bgcolor="#0000ff" clip="0,0,2,2"></layer> <layer name="a13" left=10 top=10 visibility=show bgcolor="#ff0000" clip="0,0,2,2"></layer> <div id="stars_IE" style="position:absolute;top:50px;left:50px"> <div style="position:relative;width:2px;height:2px;background:#ffffff;font-size:2px"></div> <div style="position:relative;width:2px;height:2px;background:#fff000;font-size:1px"></div> <div style="position:relative;width:2px;height:2px;background:#ffa000;font-size:1px"></div> <div style="position:relative;width:2px;height:2px;background:#ff00ff;font-size:1px"></div> <div style="position:relative;width:2px;height:2px;background:#00ff00;font-size:1px"></div> <div style="position:relative;width:2px;height:2px;background:#0000ff;font-size:1px"></div> <div style="position:relative;width:2px;height:2px;background:#FF0000;font-size:1px"></div> <div style="position:relative;width:2px;height:2px;background:#ffffff;font-size:1px"></div> <div style="position:relative;width:2px;height:2px;background:#fff000;font-size:1px"></div> <div style="position:relative;width:2px;height:2px;background:#ffa000;font-size:1px"></div> <div style="position:relative;width:2px;height:2px;background:#ff00ff;font-size:1px"></div> <div style="position:relative;width:2px;height:2px;background:#ff00ff;font-size:2px"></div> <div style="position:relative;width:2px;height:2px;background:#0000ff;font-size:1px"></div> <div style="position:relative;width:2px;height:2px;background:#FF0000;font-size:1px"></div> <div style="position:relative;width:2px;height:2px;background:#ffffff;font-size:1px"></div> <div style="position:relative;width:2px;height:2px;background:#fff000;font-size:1px"></div> <div style="position:relative;width:2px;height:2px;background:#ffa000;font-size:1px"></div> <div style="position:relative;width:2px;height:2px;background:#ff00ff;font-size:1px"></div> <div style="position:relative;width:2px;height:2px;background:#ff00ff;font-size:2px"></div> <div style="position:relative;width:2px;height:2px;background:#0000ff;font-size:1px"></div> <div style="position:relative;width:2px;height:2px;background:#FF0000;font-size:1px"></div> </div> <SCRIPT LANGUAGE="JavaScript"> <!-- Begin var out_colors = new Array(9);out_colors[0] = 'ff0000';out_colors[1] = '00ff00';out_colors[2] = '000aff';out_colors[3] = 'ff00ff';out_colors[4] = 'ffa500';out_colors[5] = 'ffff00';out_colors[6] = '00ff00';out_colors[7] = 'ffffff';out_colors[8] = 'fffff0'; var in_colors = new Array(5);in_colors[0] = 'ffa500';in_colors[1] = '55ff66';in_colors[2] = 'AC9DFC';in_colors[3] = 'fff000';in_colors[4] = 'fffff0'; var time_delay=5; var outline_x; var star_radius; var scale_x=9; var scale_y=4; var foot_steps=5; var current_steps = 0; var out_steps=90; var fade_steps=150; var end_steps=700; var Xpos = 1; var Ypos = 1; var initial_color = 'ffa000'; var Mtop = 50; var Mleft = 50; var top_tmp=Mtop; if (document.all) { //IE var star_radius= new Array(stars_IE.all.length); for ( i = 0 ; i < stars_IE.all.length ; i++ ) { star_radius[i] = window.document.body.offsetHeight / scale_y *Math.random(); } outline_x = window.document.body.offsetWidth / scale_x; } else { if (document.layers) { //NS var star_radius= new Array(14); for ( i = 0 ; i < 14 ; i++ ) { star_radius[i] = window.innerHeight / scale_y *Math.random(); } outline_x = window.innerWidth / scale_x; } } function Fireworks() { if (document.all) { //IE for ( i = 0 ; i < stars_IE.all.length ; i++ ) { c=Math.round(Math.random()*[out_colors.length-1]); if (current_steps < fade_steps) { if (current_steps < out_steps) { stars_IE.all[i].style.background=initial_color; } else { stars_IE.all[i].style.background=out_colors[c]; } stars_IE.all[i].style.top = Mtop + star_radius[i]*Math.sin(2*Math.PI*i/stars_IE.all.length)*current_steps/fade_steps; stars_IE.all[i].style.left = Mleft + star_radius[i]*Math.cos(2*Math.PI*i/stars_IE.all.length)*current_steps/fade_steps; } else { stars_IE.all[i].style.background=out_colors[c]; document.all.stars_IE.style.top = top_tmp - Math.round((fade_steps-current_steps)/15); } } } else { if (document.layers) { //NS for ( i = 0 ; i < 14 ; i++ ) { //NS var templayer = "a"+i; c=Math.round(Math.random()*[out_colors.length-1]); if (current_steps < fade_steps) { if (current_steps < out_steps) { document.layers[templayer].bgColor=initial_color; } else { document.layers[templayer].bgColor=out_colors[c]; } document.layers[templayer].top = Mtop + star_radius[i]*Math.sin(2*Math.PI*i/stars_IE.all.length)*current_steps/fade_steps; document.layers[templayer].left = Mleft + star_radius[i]*Math.cos(2*Math.PI*i/stars_IE.all.length)*current_steps/fade_steps; } else { stars_IE.all[i].style.background=out_colors[c]; document.layers[templayer].top = top_tmp - Math.round((fade_steps-current_steps)/15); } } } } current_steps+= foot_steps; T=setTimeout("Fireworks()",time_delay); if (current_steps == end_steps) { current_steps = -10; k=Math.round(Math.random()*[in_colors.length-1]); initial_color = in_colors[k]; if (document.all) { //IE Dtop = window.document.body.clientHeight - 250; Dleft = outline_x * 3.5; Mtop = Math.round(Math.random()*Dtop); Mleft = Math.round(Math.random()*Dleft); document.all.stars_IE.style.top = Mtop+document.body.scrollTop; document.all.stars_IE.style.left = Mleft+document.body.scrollLeft; top_tmp = Mtop+document.body.scrollTop; } else { if (document.layers) { //NS Dleft = window.innerWidth - 100; Dtop = window.innerHeight - 100; Mtop = Math.round(Math.random()*Dtop+window.pageYOffset); Mleft = Math.round(Math.random()*Dleft+window.pageXOffset); document.layers[templayer].top = Mtop; document.layers[templayer].left = Mleft; } } if ((Mtop < 20) || (Mleft < 20)) { Mtop += 90; Mleft += 90; } if (document.all) { //IE for ( i = 0 ; i < stars_IE.all.length ; i++ ) { star_radius[i] = window.document.body.offsetHeight / scale_y *Math.random(); } outline_x = window.document.body.offsetWidth / scale_x; } else { if (document.layers) { //NS for ( i = 0 ; i < 14 ; i++ ) { star_radius[i] = window.innerHeight / scale_y *Math.random(); } outline_x = window.innerWidth / scale_x; } } } } Fireworks(); // End --> </script> </body> </html> |