Ascii 3d Starfield In Java

Just save this source as normal .html file in your computer and open it with browser.
You can check online version of this demo in here.

<html>
<head>
<title>Web Demo!</title>
<script type="text/javascript">
var LENS = 256
var CENTX = 400
var CENTY = 300
var StarX = []
var StarY = []
var StarZ = []
var ZV = []
var rnd = Math.random()
var t
var dist
var NX
var NY

function SETPIX(X, Y, ID){
var COL = Math.round(StarZ[ID])
document.write('<span style="color: rgb('+COL+','+COL+','+COL+'); position:absolute; top:'+Y+'; left:'+X+';" id='+ID+'>*</span>')
}
function MOVEPIX(X, Y, ID){
var COL = Math.round(StarZ[ID])
document.getElementById(ID).style.top = Y
document.getElementById(ID).style.left = X
document.getElementById(ID).style.color = "rgb("+COL+","+COL+","+COL+")"
}

function UpdateField() {
for (var i = 1; i <= 100; i++){
StarZ[i] = StarZ[i] + ZV[i]
//if (StarX[i] < -400) {StarX[i] = 400}
if (StarZ[i] > 256){StarZ[i] = 0}
dist=LENS-StarZ[i]
if (dist != 0) {
NX = CENTX + (LENS*StarX[i]/dist)
NY = CENTY - (LENS*StarY[i]/dist)
MOVEPIX(NX, NY, i)
}

}
t=setTimeout("UpdateField()", 100)
}
</script>
<head>
<body bgcolor="#000000">
<script type="text/javascript">
for (var i = 1; i <= 100; i++){
rnd = Math.random()
StarX[i] = (rnd*800)-400
rnd = Math.random()
StarY[i] = (rnd*600)-300
rnd = Math.random()
StarZ[i] = rnd*255
rnd = Math.random()
ZV[i] = (rnd*(10-5))+5
}
for (var i = 1; i <= 100; i++){
dist=LENS-StarZ[i]
if (dist != 0) {
NX = CENTX + (LENS*StarX[i]/dist)
NY = CENTY - (LENS*StarY[i]/dist)
SETPIX(NX, NY, i)
}

}

UpdateField()
</script>
</body>
</html>
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.