gibney.org
:
Technology
:
Javascript
:
Experiments
:
recursive moons
(Entry Nr. 2078, by user 1 |
edit
)
<link rel="image_src" href="http://www.gibney.org/images/cat_size02/spiral_clock.png"> <style> body, html { height: 100%; } </style> <script> SpiralClock=function() { this.create=function(i) { var r=document.createElement("div"); document.body.style.backgroundColor="#000000"; document.body.appendChild(r); r.style.backgroundColor="#ff0000"; var cr=255; var cg=Math.floor(255-(i/this.nr_elements)*255); var cb=0; r.style.color="rgb("+cr+","+cg+","+cb+")"; r.style.width="2px"; r.style.height="2px"; r.style.position="fixed"; r.style.top="1px"; r.style.left="1px"; r.style.fontWeight="bold"; return r; } this.step=function() { var xa=[]; var ya=[]; var x=0; var y=0; xa[0]=x; ya[0]=y; max_x=0; max_y=0; min_x=0; min_y=0; for (var i=1;i<this.nr_elements;i++) { var radius=3; var speed=0+0.1*Math.sin(i/20)*0.0002*i; speed=Math.sin(speed/20)*100; x=x+Math.cos(this.step_nr*speed)*radius; y=y+Math.sin(this.step_nr*speed)*radius; xa[i]=x; ya[i]=y; } for (var i=0;i<this.nr_elements;i++) { this.elements[i].style.left=body_w/2+xa[i]; this.elements[i].style.top =body_h/2+ya[i]; } this.step_nr++; } this.nr_elements=400; this.elements=[]; this.step_nr=0; for (var i=0;i<this.nr_elements;i++) { this.elements[this.elements.length]=this.create(i); } } // ------------------------------------------------------------------- // Main // ------------------------------------------------------------------- body_w=document.body.offsetWidth; body_h=document.body.offsetHeight; clock1=new SpiralClock(); //clock2=new SpiralClock(); //clock3=new SpiralClock(); //clock4=new SpiralClock(); x1=setInterval (function () {clock1.step()},20); //x2=setInterval (function () {clock2.step()},40); //x3=setInterval (function () {clock3.step()},80); //x4=setInterval (function () {clock4.step()},160); document.body.removeChild(document.getElementById("mastertable")); document.body.style.height="100%"; document.body.onclick=function() { if(x1) { clearInterval(x1); //clearInterval(x2); //clearInterval(x3); //clearInterval(x4); x1=false; } else { x1=setInterval (function () {clock1.step()},20); //x2=setInterval (function () {clock2.step()},21); //x3=setInterval (function () {clock3.step()},22); //x4=setInterval (function () {clock4.step()},23); } } window.onresize=function() { window.location.href=window.location.href; } </script>
Create a new entry at this position