CJDelta
Member
- Feb 27, 2011
- 40
- 0
Check this code out.
If you want to see what it does go here >
Code:
<!-- Copyright 2010 Apolva.com :) -->
<head>
<title>Apolva.com - JS Road</title>
<style>
body{
color:#0F0;
background:#000;
font-size:17px;
}
</style>
</head>
<script>
// Maximum characters per line
var max=50;
// Speed (smaller is faster)
var speed=400;
// Clear the screen after this many lines
var clearInterval=100;
// Grass character
var grassCharacter=".";
// Start in middle of the screen.
var lastNum=Math.floor(max/2);
var currentLine=0;
var el = document.getElementById('road');
setInterval(function(){
if(currentLine>clearInterval) {
// Clear screen
road.innerHTML="";
currentLine=0;
}
currentLine++; line="";
thisNum=Math.floor(Math.random()*3)-1;
if(
(thisNum>0 && sides=="\\")
||(thisNum<0 && sides=="/")
) thisNum=0; // Make it a straight piece, to avoid jolts.
lastNum=lastNum+thisNum;
if(lastNum>50) lastNum=50;
if(lastNum<1) lastNum=1;
// Left
for(i=0;i<lastNum;i++){
line+=grassCharacter;
}
if(thisNum>0) sides="/";
else if(thisNum==0) sides="|";
else sides="\\";
// Display road line
line+=sides+" "+(currentLine%2==0 ? "|" :" ")+" "+sides;
// Right side
for(i=0;i<(max-lastNum);i++){
line+=grassCharacter;
}
road.innerHTML=line+"<br />\r\n"+road.innerHTML;
},speed);
</script>
<pre id='road'>>> Welcome to JS Road!</pre>
If you want to see what it does go here >
You must be registered for see links