很酷的用JavaScript寫的3D旋轉效果

來源:互聯網
上載者:User

 

 

<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>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.