很酷的用JavaScript写的3D旋转效果

来源:互联网 发布:信息发布平台源码 编辑:程序博客网 时间:2024/05/20 06:25

<html>
<head>
<title>Rotating 3D Cube in JavaScript</title>
<style type="text/css">
body{
 background:#000;
 color:#FF0;
 height:100%;
 margin:0;
 padding:0;
 width:100%;
}
b{
 position:absolute;
}
a{color:gold;}
a:hover{color:#FF0;}
address{
 font-family:Georgia;
 font-style:normal;
 bottom:10px;
 position:absolute;
 right:10px;
 text-align:right;
}
</style>
</head>
<body onmousemove="a = event.clientX / 99; b = event.clientY / 99;">

<script type="text/javascript">

var dimension = 1;
var a = 0, b = 0

var i = 27;
while (i--)
{
 document.write('<b id="l' + i + '">+</b>');
}

function f()
{
 i = 0;
 for (x =- dimension; x <= dimension; x += dimension)
 {
  for (y =- dimension; y <= dimension; y += dimension)
  {
   for (z =- dimension; z <= dimension; z += dimension)
   {
    u = x;
    v = y;
    w = z;
    u2 = u * Math.cos(a) - v * Math.sin(a);
    v2 = u * Math.sin(a) + v * Math.cos(a);
    w2 = w;
    u = u2; v = v2; w = w2;
    u2 = u;
    v2 = v * Math.cos(b) - w * Math.sin(b);
    w2 = v * Math.sin(b) + w * Math.cos(b);
    u = u2; v = v2; w = w2;
    var c = Math.round((w + 2) * 70);
    if (c < 0) c = 0;
    if (c > 255) c = 255;
    with (document.all('l' + i).style)
    {
     left = 300 + u * (w + 2) * 50;
     top  = 300 + v * (w + 2) * 50;
     color = 'rgb(' + c + ', ' + c + ', 0)';
     fontSize = (w + 2) * 16 + "px";
    }
    i++;
   }
  }
 }
}

setInterval('f()', 9);

</script>

<address>&copy; <a href="http://maettig.com/">Thiemo M&auml;ttig</a>,
created 2007-09-04<br />
<a href="./">More JavaScript experiments &raquo;</a></address>

</body>
</html>


本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/facepp/archive/2008/10/21/3118742.aspx