【欣赏是一种什么】欣赏一下火星人写的JS

更新时间:2019-10-24 来源:最新动态 点击:

【www.hzclsc.cn--最新动态】

前言:
据BBC报道美国一火星探测器在绕火探测过程中检测到一神秘信号,后经贝尔实验室解析后发现是一段母牛坐蒸笼的JS,本人不敢独享,特转来献给JE的兄弟姐妹.出处:[转火星探测器]
说明:拷贝代码下来另存为html即可运行。
!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01//EN http://www.w3.org/TR/html4/strict.dtd
html
head
title Wanna tell her - interactive DHTML /title
meta http-equiv= imagetoolbar content= no
style type= text/css
html {
overflow: hidden;
}
body {
position: absolute;
margin: 0px;
padding: 0px;
background: #fff;
width: 100%;
height: 100%;
}
#screen {
position: absolute;
left: 10%;
top: 10%;
width: 80%;
height: 80%;
background: #fff;
}
#screen img {
position: absolute;
cursor: pointer;
width: 0px;
height: 0px;
-ms-interpolation-mode:nearest-neighbor;
}
#bankImages {
visibility: hidden;
}
#FPS {
position: absolute;
right: 5px;
bottom: 5px;
font-size: 10px;
color: #666;
font-family: verdana;
}

/style

script type= text/javascript
/* ==== Easing function ==== */
var Library = {};
Library.ease = function () {
this.target = 0;
this.position = 0;
this.move = function (target, speed) {
this.position += (target - this.position) * speed;
}
}

var tv = {
/* ==== variables ==== */
O : [],
fps : 0,
screen : {},
angle : {
x : new Library.ease(),
y : new Library.ease()
},
camera : {
x  : new Library.ease(),
y  : new Library.ease()
},
create3DHTML : function (i, x, y, z, sw, sh) {
/* ==== create HTML image element ==== */
var o = document.createElement("img");
o.src = i.src;
tv.screen.obj.appendChild(o);
/* ==== 3D coordinates ==== */
o.point3D = {
x  : x,
y  : y,
z  : new Library.ease(),
sw : sw,
sh : sh,
w  : i.width,
h  : i.height
};
o.point3D.z.target = z;
/* ==== push object ==== */
o.point2D = {};
tv.O.push(o);

/* ==== on mouse over event ==== */
o.onmouseover = function () {
if (this != tv.o) {
this.point3D.z.target = tv.mouseZ;
tv.camera.x.target = this.point3D.x;
tv.camera.y.target = this.point3D.y;
if (tv.o) tv.o.point3D.z.target = 0;
tv.o = this;
}
return false;
}

/* ==== on mousedown event ==== */
o.onmousedown = function () {
if (this == tv.o) {
if (this.point3D.z.target == tv.mouseZ) this.point3D.z.target = 0;
else {
tv.o = false;
this.onmouseover();
}
}
}

/* ==== main 3D function ==== */
o.animate = function () {
/* ==== 3D coordinates ==== */
var x = this.point3D.x - tv.camera.x.position;
var y = this.point3D.y - tv.camera.y.position;
this.point3D.z.move(this.point3D.z.target, this.point3D.z.target ? .15 : .08);
/* ==== rotations ==== */
var xy = tv.angle.cx * y  - tv.angle.sx * this.point3D.z.position;
var xz = tv.angle.sx * y  + tv.angle.cx * this.point3D.z.position;
var yz = tv.angle.cy * xz - tv.angle.sy * x;
var yx = tv.angle.sy * xz + tv.angle.cy * x;
/* ==== 2D transform ==== */
var scale = tv.camera.focalLength / (tv.camera.focalLength + yz);
x = yx * scale;
y = xy * scale;
var w = Math.round(Math.max(0, this.point3D.w * scale * this.point3D.sw));
var h = Math.round(Math.max(0, this.point3D.h * scale * this.point3D.sh));
/* ==== HTML rendering ==== */
var o  = this.style;
o.left  = Math.round(x + tv.screen.w - w * .5) + "px";
o.top  = Math.round(y + tv.screen.h - h * .5) + "px";
o.width  = w + "px";
o.height = h + "px";
o.zIndex = 10000 + Math.round(scale * 1000);
}
},

/* ==== init script ==== */
init : function (structure, FL, mouseZ, rx, ry) {
this.screen.obj = document.getElementById("screen");
this.screen.obj.onselectstart = function () { return false; }
this.screen.obj.ondrag  = function () { return false; }
this.mouseZ = mouseZ;
this.camera.focalLength = FL;
this.angle.rx = rx;
this.angle.ry = ry;
/* ==== create objects ==== */
var i = 0, o;
while( o = structure[i++] )
this.create3DHTML(o.img, o.x, o.y, o.z, o.sw, o.sh);
/* ==== start script ==== */
this.resize();
mouse.y = this.screen.y + this.screen.h;
mouse.x = this.screen.x + this.screen.w;
/* ==== loop ==== */
setInterval(tv.run, 16);
setInterval(tv.dFPS, 1000);
},

/* ==== resize window ==== */
resize : function () {
var o = tv.screen.obj;
if (o) {
tv.screen.w = o.offsetWidth / 2;
tv.screen.h = o.offsetHeight / 2;
for (tv.screen.x = 0, tv.screen.y = 0; o != null; o = o.offsetParent) {
tv.screen.x += o.offsetLeft;
tv.screen.y += o.offsetTop;
}
}
},

/* ==== main loop ==== */
run : function () {
tv.fps++;
/* ==== motion ease ==== */
tv.angle.x.move(-(mouse.y - tv.screen.h - tv.screen.y) * tv.angle.rx, .1);
tv.angle.y.move( (mouse.x - tv.screen.w - tv.screen.x) * tv.angle.ry, .1);
tv.camera.x.move(tv.camera.x.target, .025);
tv.camera.y.move(tv.camera.y.target, .025);
/* ==== angles sin and cos ==== */
tv.angle.cx = Math.cos(tv.angle.x.position);
tv.angle.sx = Math.sin(tv.angle.x.position);
tv.angle.cy = Math.cos(tv.angle.y.position);
tv.angle.sy = Math.sin(tv.angle.y.position);
/* ==== loop through images ==== */
var i = 0, o;
while( o = tv.O[i++] ) o.animate();
},

/* ==== trace frames per seconds ==== */
dFPS : function () {
document.getElementById("FPS").innerHTML = tv.fps + " FPS";
tv.fps = 0;
}
}

/* ==== global mouse position ==== */
var mouse = {
x : 0,
y : 0
}
document.onmousemove = function(e) {
if (window.event) e = window.event;
mouse.x = e.clientX;
mouse.y = e.clientY;
return false;
}

/* ==== starting script ==== */
onload = function() {
onresize = tv.resize;
/* ==== build grid ==== */
var img = document.getElementById("bankImages").getElementsByTagName("img");
var structure = [];
for (var i = -300; i = 300; i += 120)
for (var j = -300; j = 300; j += 120)
structure.push({ img:img[0], x:i, y:j, z:0, sw:.5, sh:.5 });
/* ==== let"s go ==== */
tv.init(structure, 350, -200, .005, .0025);
}

/script
/head

body

div id= screen /div

div id= bankImages
img alt= src= http://avatar.profile.csdn.net/D/0/9/2_cicadu.jpg
/div
div id= FPS /div

/body
/html

本文来源:http://www.hzclsc.cn/shouyou/35474.html

为您推荐

[杀戮尖塔遗物大全最新]杀戮尖塔有哪些遗物 杀戮尖塔遗物大全介绍

杀戮尖塔有哪些遗物?杀戮尖塔有许多遗物,有些遗物的作用非常巨大,感谢BGod为大家带来杀戮尖塔各遗物使用心得,供各位玩家们参考。下面就一起来看看杀戮尖塔遗物大全介绍吧。首先说一下稳健的打法,适用于不想策略与战棋

2020-12-18 23:05:07  

【高通骁龙670跑分多少钱】高通骁龙670跑分多少 高通670处理器怎么样

高通骁龙670处理器是骁龙660的继任者,之前在GeekBench 4跑分单核心超1860、多核心超5250,相比于骁龙660单核提升约10%,但多核心反而下降了10%,现在又有了最新的消息,赶快来了硬件报道

2020-12-17 07:04:32  

全面战争三国什么时候可以玩_全面战争三国什么时候出 全面战争三国发售日期

全面战争三国什么时候出?相信很多玩家朋友们都非常的期待全面战争三国的发售时间了,下面我们就来看一看官方最新公布的全面战争三国发售日期,希望对期待这款游戏的玩家朋友们有所参考。游戏名称:全面战争三国1K策略与战棋

2020-12-16 11:04:57   三国全面战争什么时候能玩   三国全面战争什么时候发售  

超级机器人大战x参战机体有哪些|超级机器人大战X参战机体有哪些 超级机器人大战X参战机体一览

超级机器人大战X参战机体有哪些?这次南梦宫公布了超级机器人大战最新作X,那么这次系列登场的作品机体有哪些了,下面我们就来看一看超级机器人大战X参战机体一览吧。超级机器人大战X参战机体一览之前南梦宫万代

2020-12-12 07:04:05  

【京东饭粒app】京东饭粒是什么 京东饭粒商城有什么用

现在的人对于线上消费喜欢维持一种微妙的平衡,既保证消费品质,也要经济实惠,追求“高性价比”,讲究“精打细算”可说是如今电商消费时代都在保持的优良传统。因此坐等某类品牌打折,或坚持到节假日、超级品牌日再厂商动态

2020-12-09 23:04:54   京东饭粒怎么用   京东饭粒没了