花火もどき
|
| Sample |
|
ここをクリックして新しいウインドウを開いてください。
|
| ソース |
<HTML>
<HEAD>
<TITLE>Java-Script</TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!--
var xpos0=0;var ypos0=0;
n=30;
var _width = 800;
var _height = 800;
xpos=new Array();
ypos=new Array();
i=new Array();
l=new Array();
dot=new Array();
thiscol=new Array();
var thisc1;
var thisc2;
var thisc3;
var thiscol1;
var thiscol2;
var thiscol3;
var thiscol4;
var thiscol5;
var p=0;
timerID=0;
for (m=1;m<(n+1);m++){
thisc1=Math.round(255*Math.random());
thisc2=Math.round(255*Math.random());
thisc3=Math.round(255*Math.random());
thiscol1=thisc1.toString(16);
thiscol2=thisc2.toString(16);
thiscol3=thisc3.toString(16);
thiscol4=thiscol1+thiscol2+thiscol3;
thiscol5=eval("thiscol4");
thiscol[m] =thiscol5;
}
function start_hanabi2() {
_width =300;
_height=300;
xpos0 = _width+2;
ypos0 = _height-2;
for (m=1;m<(n+1);m++){
xpos[m] = _width+4*Math.random();
ypos[m] = _height-4*Math.random();
i[m]=xpos[m]-xpos0;
l[m]=ypos[m]-ypos0;
}
p=0;
start_hanabi();
}
function start_hanabi() {
p=p+1;
for (m=1;m<(n+1);m++){
document.all["dot["+m+"]"].style.display="block";
document.all["dot["+m+"]"].style.pixelTop = ypos[m];
document.all["dot["+m+"]"].style.pixelLeft = xpos[m];
xpos[m]=xpos[m]+2*i[m];
ypos[m]=ypos[m]+2*l[m];
if ((xpos[m]<=5)||(ypos[m]<=5)){
xpos[m] = _width+4*Math.random();
ypos[m] = _height-4*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+4*Math.random();
ypos[m] = _height-4*Math.random();
i[m]=xpos[m]-xpos0;
l[m]=ypos[m]-ypos0;
}
}
if (p>=70) {
p=70;
for (m=1;m<(n+1);m++){
document.all["dot["+m+"]"].style.display="none";
clearTimeout(timerID);
}
}
timerID=setTimeout("start_hanabi()",1);
}
//-->
</SCRIPT>
</HEAD>
<body bgcolor=black>
<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: 1px; LEFT: 1px; width:1;\"><font color=#"
+thiscol[m]+"size=1>★</font></div>");
}
//-->
</SCRIPT>
<FORM>
<INPUT Type=button VALUE="花火もどきスタート" onClick=start_hanabi2()>
<INPUT Type=button VALUE="ウインドウを閉じる" onClick=window.close()>
</FORM>
<br><br>
</BODY>
</HTML>
|
| ワンポイント解説 |
|
_width =300; _height=300; で、開始位置を設定しています。 onClick=start_hanabi2() で、スタートしています。 |