Su enlace violín no estaba trabajando para mí debido a una velocidad de intervalo que falta, debe utilizar getElementById
también (simplemente porque funciona en Internet Explorer no significa que sea multi-navegador).
Aquí, en horquilla, usarlo éste en su lugar:
http://jsfiddle.net/spechackers/hJhCz/
También he limpiado el código en su primer enlace:
<pre id="p">
<script type="text/javascript">
var charMap=['p','.'];
var n=0;
function myInterval()
{
n+=7;//this is the amount of screen to "scroll" per interval
var outString="";
//this loop will execute exactly 4096 times. Once for each character we will be working with.
//Our display screen will consist of 32 lines or rows and 128 characters on each line
for(var i=64; i>0; i-=1/64)
{
//Note mod operations can result in numbers like 1.984375 if working with non-integer numbers like we currently are
var mod2=i%2;
if(mod2==0)
{
outString+="\n";
}else{
var tmp=(mod2*(64/i))-(64/i);//a number between 0.9846153846153847 and -4032
tmp=tmp+(n/64);//still working with floating points.
tmp=tmp^(64/i);//this is a bitwise XOR operation. The result will always be an integer
tmp=tmp&1;//this is a bitwise AND operation. Basically we just want to know if the first bit is a 1 or 0.
outString+=charMap[tmp];
}
}//for
document.getElementById("p").innerHTML=outString;
}
myInterval();
setInterval(myInterval,64);
</script>
</pre>
El resultado del código en el dos enlaces que proporcionó son muy diferentes el uno del otro. Sin embargo, la lógica en el código es bastante similar. Ambos usan un bucle for para recorrer todos los caracteres, una operación de modulación en un número no entero y una operación xor bitwise
.
Cómo funciona todo, básicamente todo I can tell you is to pay attention to the variables changing as the input and output change
.
Toda la lógica parece ser una especie de bitwise
forma críptica de decidir cuál de los 2 caracteres o un salto de línea agregar a la página.
No lo sigo del todo desde un calculus or trigonometry
tipo de perspectiva.
Como se menciona la URL, la escena es un checkboard de trazado de rayos con el punto de vista de movimiento. Ver por ejemplo http://www.cs.utah.edu/~shirley/classes/cs684_98/students/psutton/hw3/raytracer.html. – lhf