游来游去的小鱼
来源:互联网 发布:电梯调度算法 编辑:程序博客网 时间:2024/06/10 18:45
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>particle-4</title>
<meta http-equiv="imagetoolbar" content="no">
<style type="text/css">
html {
overflow: hidden;
}
body {
margin: 0px;
padding: 0px;
background: #ccc;
position: absolute;
width: 100%;
height: 100%;
cursor: crosshair;
}
#SF {
position: absolute;
left: 203px;
top: 28px;
width: 70%;
height: 70%;
overflow: hidden;
background: #fff;
}
#SF img {
cursor: pointer;
position: absolute;
}
#FPS {
position: absolute;
right: 5px;
bottom: 5px;
font-size: 10px;
color: #666;
font-family: courier;
}
</style>
<script type="text/javascript">
//parentNode.removeChildeg Rd朣_MR剉 <book> CQ }0
var D = 150;
var NB = 15;
var o = [];
var xm = 0;
var ym = 0;
var R = 1 / (D * D);
var fps = 0;
var M = 0;
function resize() {
nx = document.getElementById("SF").offsetWidth;
ny = document.getElementById("SF").offsetHeight;
}
onresize = resize;
obZ = function() {
this.x = Math.random() * nx;
this.y = Math.random() * ny;
this.vx = 0;
this.vy = 0;
this.O = new RotImg(this, document.getElementById("SF"), [
["p1", 0,0],
["p2", 8,-30],
["p2", 8,30],
["p5", 20,180]
]);
}
function RotImg(parent, obj, param){
this.param = param;
for(var i in param){
s = param[i];
m = document.createElement("img");
m.src = document.getElementById(s[0]).src;
m.obj = parent;
obj.appendChild(m);
param[i][0] = m;
param[i][3] = m.width ;
param[i][4] = m.height ;
param[i][2] *= Math.PI/180;
}
this.position = function (x,y, angle){
with (this) {
for(var i in param){
a = ( angle + param[i][2]);
r = param[i][1];
with(param[i][0].style){
left = Math.round(-param[i][3] + x + Math.cos(a) * r) + 'px';
top = Math.round(-param[i][4] + y + Math.sin(a) * r) + 'px';
}
}
}
}
}
function mainloop(){
M--;
fps++;
for(var i=0; i<NB; i++){
with(o[i]){
for(var j=0; j<NB; j++){
B = o[j];
if(i != j){
dx = x - B.x;
dy = y - B.y;
d = (dx * dx + dy * dy);
if(d < 2 * D * D){
w = Math.exp(-(dx * dx * R)) * Math.exp(-(dy * dy * R));
// cohesion
vx -= 1.8 * w * dx;
vy -= 1.8 * w * dy;
// avoidance
if(B.x<x) vx += 100 * w; else vx -= 100 * w;
if(B.y<y) vy += 100 * w; else vy -= 100 * w;
// alignment
b = w * B.vx;
if(Math.abs(b)>10)b = (b / Math.abs(b)) * 10;
vx += b;
b = w * B.vy;
if(Math.abs(b)>10)b = (b / Math.abs(b)) * 10;
vy += b;
}
}
}
if(M > 0){
dx = x - xm;
dy = y - ym;
w = Math.exp(-(dx * dx * R)) * Math.exp(-(dy * dy * R));
if(xm < x) ex = w; else ex = -w;
if(ym < y) ey = w; else ey = -w;
vx += 1000 * NB * ex;
vy += 1000 * NB * ey;
}
vx *= .98;
vy *= .98;
x += vx / (NB * 2000);
y += vy / (NB * 2000);
if(x > nx + 10) x = -10; else if(x < -10) x = nx + 10;
if(y > ny + 10) y = -10; else if(y < -10) y = ny + 10;
O.position(x, y, Math.atan2(vy, vx));
}
}
setTimeout("mainloop();", 1);
}
onload = function(){
resize();
xm = 20000;
ym = 20000;
for(var i=0; i<NB; i++)o[i] = new obZ()
mainloop();
setInterval("document.getElementById('FPS').innerHTML=fps+' fps';fps=0", 1000);
}
</script>
</head>
<body>
<div id="SF"></div>
<div style="visibility: hidden">
<img id="p1" src="http://www.lanrentuku.com/down/js/images/12476486070.gif">
<img id="p2" src="http://www.lanrentuku.com/down/js/images/12476486071.gif">
<img id="p5" src="http://www.lanrentuku.com/down/js/images/12476486072.gif">
</div>
<div id="FPS"></span>
</body>
</html>
- 游来游去的小鱼
- 游来游去的小鱼
- 鼠标事件之游来游去的小鱼
- 小鱼的做法
- 小鱼的爱情故事
- 给小鱼的
- 小鱼的悲剧
- 思想的小鱼
- 善意的小鱼小虾
- 乐乐的小鱼
- 我的小鱼死了
- 小鱼的游泳时间
- 小鱼的游泳时间
- 小鱼的数字游戏
- 小鱼的游泳时间
- 小鱼的数字游戏
- 小鱼的游泳时间
- 小鱼的游泳时间
- packageInfo相关类应用
- 编写一个实现tag接口的实现类
- 关于网站建设整体策划流程
- 总结C语言time.h头文件中日期和时间的处理
- smarty(二)
- 游来游去的小鱼
- VSTO将Outlook批量邮件导出Word
- MultiAutoCompleteTextView和AutoCompleteTextView两个自动完成功能控件的使用
- PHP精华
- smarty模板
- 页面置换 读操作系统概念第六版
- XP上远程Putty+Xming使用方法
- 程序员面试100题之九:求子数组的最大和
- Android—Http连接之GET/POST请求