花火もどき−2 |
Sample |
ここをクリックして新しいウインドウを開いてください。
|
ソース |
<HTML><HEAD> <TITLE>Java-Script</TITLE> <SCRIPT LANGUAGE="JavaScript"> <!-- var xpos0=0;var ypos0=0; n=30; var _width = 800; var _height = 800; _width = screen.width*4/6*Math.random(); _height= screen.height*3/6*Math.random(); xpos0 = _width+5; ypos0 = _height-3; xpos=new Array(); ypos=new Array(); i=new Array(); l=new Array(); dot=new Array(); thisl=new Array(); var this1; var this2; var this3; var thisol1; var thisol2; var thisol3; var thisol4; var thisol5; for (m=1;m<(n+1);m++){ xpos[m] = _width+10*Math.random(); ypos[m] = _height-10*Math.random(); this1=Math.round(255*Math.random()); this2=Math.round(255*Math.random()); this3=Math.round(255*Math.random()); thisol1=this1.toString(16); thisol2=this2.toString(16); thisol3=this3.toString(16); thisol4=thisol1+thisol2+thisol3; thisol5=eval("thisol4"); thisl[m] =thisol5; i[m]=xpos[m]-xpos0; l[m]=ypos[m]-ypos0; } var p=0; timeID=0; function hanabi() { p=p+1; for (m=1;m<(n+1);m++){ document.all["dot["+m+"]"].style.pixelTop = ypos[m]; document.all["dot["+m+"]"].style.pixelLeft = xpos[m]; xpos[m]=xpos[m]+i[m]; ypos[m]=ypos[m]+l[m]; l[m]=l[m]+0.2; if ((xpos[m]<=5)||(ypos[m]<=5)){ xpos[m] = _width+10*Math.random(); ypos[m] = _height-10*Math.random(); i[m]=xpos[m]-xpos0; l[m]=ypos[m]-ypos0; } else if ((xpos[m]>=screen.width*8/10)||(ypos[m]>=screen.height*7/10)){ xpos[m] = _width+10*Math.random(); ypos[m] = _height-10*Math.random(); i[m]=xpos[m]-xpos0; l[m]=ypos[m]-ypos0; } } if (p>40){ _width = screen.width*4/6*Math.random(); _height= screen.height*3/6*Math.random(); xpos0 = _width+5; ypos0 = _height-3; p=0; for (m=1;m<(n+1);m++){ xpos[m] = _width+10*Math.random(); ypos[m] = _height-10*Math.random(); this1=Math.round(255*Math.random()); this2=Math.round(255*Math.random()); this3=Math.round(255*Math.random()); thisol1=this1.toString(16); thisol2=this2.toString(16); thisol3=this3.toString(16); thisol4=thisol1+thisol2+thisol3; thisol5=eval("thisol4"); thisl[m] =thisol5; i[m]=xpos[m]-xpos0; l[m]=ypos[m]-ypos0; } } timeID=setTimeout("hanabi()",1); } //--> </SCRIPT> </HEAD> <body bgcolor=black onLoad="hanabi()"> <SCRIPT LANGUAGE="JavaScript"> <!-- for (m=1;m<(n+1);m++){ document.write("<div id=\"dot["+ m +"]\" style=\"POSITION: absolute; Z-INDEX: " + m +" VISIBILITY: visible; TOP: 15px; LEFT: 15px; width:1;\"><font color=#" +thisl[m]+"size=1>★</font></div>"); } //--> </SCRIPT> <FORM> <INPUT TYPE=button VALUE="ウインドウを閉じる" onClick=window.close()> </FORM> </BODY> </HTML> |
ワンポイント解説 |
_width = screen.width*4/6*Math.random(); _height= screen.height*3/6*Math.random(); で、開始位置をランダムに設定しています。 |