JavaScripts -> Animation -> Starfield Simulation

Wie der bekannte Windows-Bildschirmschoner simuliert dieses Script einen Flug durch die Galaxie.

Kompatibilität getestet:
Beispiel Anzeigen >>

Script-Code

<script type="text/javascript">
<!--
//Starfield Simulation v1.0 (c) 2003 Triple-M / http://www.htmlarsenal.de

//Benutzung/Usage: Script mit dem Inhalt / with the content starfield();

var ssnum=30; //Anzahl der Sterne / number of Stars
var ssspd=50; //Geschwindigkeit / Speed

//Bitte ab hier nichts mehr verändern / Please do not change anything from here on

var ssw=screen.availWidth;
var ssh=screen.availHeight-30;
var sshw=Math.floor(ssw/2);
var sshh=Math.floor(ssh/2);

var ssx=new Array(ssnum);
var ssy=new Array(ssnum);
var ssz=new Array(ssnum);

function ssup() {
  var el;
  for(var i=0;i<ssnum;i++) {
    ssx[i]=ssx[i]+Math.floor((ssx[i]-sshw)/((21-ssz[i])/2));
    ssy[i]=ssy[i]+Math.floor((ssy[i]-sshh)/((21-ssz[i])/2));
    ssz[i]++;
    if(ssz[i]==20) {
      ssx[i]=Math.floor(Math.random()*sshw+(sshw/2));
      ssy[i]=Math.floor(Math.random()*sshh+(sshh/2));
      ssz[i]=0;
    }
    el=document.getElementById("ss"+i);
    el.style.left=ssx[i];
    el.style.top=ssy[i];
    el.style.fontSize=(10+ssz[i]*2);
  }

}

function starfield() {
  for(var i=0;i<ssnum;i++) {
    ssx[i]=Math.floor(Math.random()*ssw);
    ssy[i]=Math.floor(Math.random()*ssh);
    ssz[i]=Math.floor(Math.random()*20);
    document.write('<div id="ss'+i+'" style="position:absolute; font-size:'+(10+ssz[i]*2)+'px; left:'+ssx[i]+'px; top:'+ssy[i]+'px">.</div>');
  }
  window.setInterval("ssup()",ssspd);

}
//-->
</script>