<html>
<head>
<title></title>
<style type="text/css">
BODY {
background-color:#000000;
color:#FFFFFF;
}
</style>
</head>
<body>
<script type="text/javascript">
(function(){
var global = this;
var globalName = 'starField';
var numberOfStars = 30;
var depthDimentsion = 2000;
var viewingDepth = 0.0001;
var forwardVelocity = 2.5;
var d = depthDimentsion*(viewingDepth/100);
var planeDepth = depthDimentsion - d;
var fv = planeDepth*(forwardVelocity/100);
var zMultiplier = (depthDimentsion)/d;
var starObjs, starHTML;
var posMod, sy, sx, windowCenterY, windowCenterX;
var scaleXAdjust, scaleYAdjust;
if((document.layers)&&(this.Layer)){
starHTML = [
'<layer id=\"stars','',
'\" left=\"0\" top=\"0\" width=\"1\" height=\"1"',
' bgColor=\"#FFFFFF\"><\/layer>'];
}else{
starHTML = [
'<div id="stars','',
'" style="position:absolute;width:1px;overflow:',
'hidden;height:1px;background-color:#FFFFFF;',
'font-size:1px"><\/div>'];
}
function compatModeTest(obj){
if((document.compatMode)&&
(document.compatMode.indexOf('CSS') != -1)&&
(document.documentElement)){
return document.documentElement;
}else if(document.body){
return document.body;
}else{
return obj;
}
}
function getWindowState(){
var global = this;
var readScroll = {scrollLeft:NaN,scrollTop:NaN};
var readSizeC = {clientWidth:NaN,clientHeight:NaN};
var readSizeI = {innerWidth:NaN,innerHeight:NaN};
var readScrollX = 'scrollLeft';
var readScrollY = 'scrollTop';
function getWidthI(){return readSizeI.innerWidth;}
function getWidthC(){return readSizeC.clientWidth|0;}
function getHeightI(){return readSizeI.innerHeight;}
function getHeightC(){return readSizeC.clientHeight|0;}
function getHeightSmart(){
return retSmaller(getHeightI(), getHeightC());
}
function getWidthSmart(){
return retSmaller(getWidthI(), getWidthC());
}
function setInnerWH(){
theOne.getWidth = getWidthI;
theOne.getHeight = getHeightI;
}
function retSmaller(inr, other){
if(other > inr){
setInnerWH();
return inr;
}else{
return other;
}
}
var theOne = {
getScrollX:function(){return readScroll[readScrollX]|0;},
getScrollY:function(){return readScroll[readScrollY]|0;},
getWidth:getWidthC,
getHeight:getHeightC
};
function main(){return theOne;}
function rankObj(testObj){
var dv,dhN;
if(testObj&&(typeof testObj.clientWidth == 'number')&&
(typeof testObj.clientHeight == 'number')){
if(((dv = global.innerHeight - testObj.clientHeight) >= 0)&&
((dh = global.innerWidth - testObj.clientWidth) >= 0)){
if(dh == dv){
return 0;
}else if((dh&&!dv)||(dv&&!dh)){
return (dh+dv);
}
}
}
return NaN;
}
if((typeof global.innerHeight == 'number')&&
(typeof global.innerWidth == 'number')){
readSizeI = global;
var bodyRank = rankObj(document.body);
var rankDocEl = rankObj(document.documentElement);
var selEl = null;
if(!isNaN(bodyRank)){
if(!isNaN(rankDocEl)){
if(bodyRank < rankDocEl){
selEl = document.body;
}else if(bodyRank > rankDocEl){
selEl = document.documentElement;
}else{
selEl = compatModeTest(document.body);
}
}else{
selEl = document.body;
}
}else if(!isNaN(rankDocEl)){
selEl = document.documentElement;
}
if(selEl){
readSizeC = selEl
theOne.getWidth = getWidthSmart;
theOne.getHeight = getHeightSmart;
}else{
setInnerWH();
}
}else{
readSizeC = compatModeTest(readSizeC);
}
if((typeof global.pageYOffset == 'number')&&
(typeof global.pageXOffset == 'number')){
readScroll = global;
readScrollY = 'pageYOffset';
readScrollX = 'pageXOffset';
}else{
readScroll = compatModeTest(readScroll);
}
return (getWindowState = main)();
}
var windowState = getWindowState();
function readWindow(){
scaleYAdjust = (((windowCenterY =
(windowState.getHeight() >>1)) - 16)*
zMultiplier);
scaleXAdjust = (((windowCenterX =
(windowState.getWidth() >> 1)) - 16)*
zMultiplier);
sy = windowCenterY + windowState.getScrollY();
sx = windowCenterX + windowState.getScrollX();
}
function getStyleObj(id){
var obj = null;
if(document.getElementById){
obj = document.getElementById(id);
}else if(document.all){
obj = document.all[id];
}else if(document.layers){
obj = document.layers[id];
}
return ((typeof obj != 'undefined')&&
(typeof obj.style != 'undefined'))?
obj.style:obj;
}
function starObj(id, parent, prv){
var next,reset;
var divClip, div = getStyleObj("stars"+id);
var y,x,z,v,dx,dy,dm,dm2,px,py,widthPos,temp;
(reset = function(){
px = Math.random()<0.5 ? +1 : -1;
py = Math.random()<0.5 ? +1 : -1;
y = ((Math.random()*Math.random()*
scaleYAdjust)+windowCenterY);
x = ((Math.random()*Math.random()*
scaleXAdjust)+windowCenterX);
widthPos = (x + zMultiplier);
z = 0;
})();
z = Math.random()*planeDepth*0.8;
function step(){
temp = x * (v = d/(depthDimentsion - z));
dm = ((dm2 = ((widthPos * v)-temp)|0)>>1);
dy = (y * v);
dx = (temp);
}
if(div){
if(!posMod){
posMod = (typeof div.top == 'string')?'px':0;
}
divClip = ((typeof div.clip != 'undefined')&&
(typeof div.clip != 'string'))?
div.clip:div;
this.position = function(){
step();
if(((z += fv) >= planeDepth)||
((dy+dm) > windowCenterY)||
((dx+dm) > windowCenterX)){
reset();
step();
dm = 0;
}
div.top = ((sy+(py*dy)-dm)|0)+posMod;
div.left = ((sx+(px*dx)-dm)|0)+posMod;
divClip.width = (divClip.height = dm2+posMod);
next.position();
};
}else{
this.position = function(){return;};
}
if(++id < numberOfStars){
next = new starObj(id, parent)
}else{
next = parent
}
}
function init(){
if(!getStyleObj("stars"+(numberOfStars-1))){
setTimeout(starField, 200);
}else{
readWindow();
starObjs = new starObj(0, init);
init.act();
}
};
init.position = function(){return;}
init.act = function(){
readWindow();
starObjs.position();
setTimeout(init.act,50);
};
init.act.toString = function(){
return globalName+'.act()';
};
init.toString = function(){
while(global[globalName])globalName += globalName;
global[globalName] = this;
return globalName+'()';
};
for(var c = numberOfStars;c--;){
starHTML[1] = c;
document.write(starHTML.join(''));
}
setTimeout(init, 200);
})();
</script>
</body>
</html>
© Richard Cornford 2004