这段javascript代码真炫,设计思路看不懂,高手来看看

wudizaizai 2015-08-25 07:24:02
<html>
<head>
<title>star</title>
<script type="text/javascript">
window.onload = function () {
C = Math.cos; // cache Math objects
S = Math.sin;
U = 0;
w = window;
j = document;
d = j.getElementById("c");
c = d.getContext("2d");
W = d.width = w.innerWidth;
H = d.height = w.innerHeight;
c.fillRect(0, 0, W, H); // resize <canvas> and draw black rect (default)
c.globalCompositeOperation = "lighter"; // switch to additive color application
c.lineWidth = 0.2;
c.lineCap = "round";
var bool = 0,
t = 0; // theta
d.onmousemove = function (e) {
if(window.T) {
if(D==9) { D=Math.random()*18; f(1); }
clearTimeout(T);
}
X = e.pageX; // grab mouse pixel coords
Y = e.pageY;
a=0; // previous coord.x
b=0; // previous coord.y
A = X, // original coord.x
B = Y; // original coord.y
R=(e.pageX/W * 999>>0)/999;
r=(e.pageY/H * 999>>0)/999;
U=e.pageX/H * 360 >>0;
D=9;
g = 360 * Math.PI / 180;
T = setInterval(f = function (e) { // start looping spectrum
c.save();
c.globalCompositeOperation = "source-over"; // switch to additive color application
if(e!=1) {
c.fillStyle = "rgba(0,0,0,0.02)";
c.fillRect(0, 0, W, H); // resize <canvas> and draw black rect (default)
}
c.restore();
i = 25; while(i --) {
c.beginPath();
if(D > 450 || bool) { // decrease diameter
if(!bool) { // has hit maximum
bool = 1;
}
if(D < 0.1) { // has hit minimum
bool = 0;
}
t -= g; // decrease theta
D -= 0.1; // decrease size
}
if(!bool) {
t += g; // increase theta
D += 0.1; // increase size
}
q = (R / r - 1) * t; // create hypotrochoid from current mouse position, and setup variables (see: http://en.wikipedia.org/wiki/Hypotrochoid)
x = (R - r) * C(t) + D * C(q) + (A + (X - A) * (i / 25)) + (r - R); // center on xy coords
y = (R - r) * S(t) - D * S(q) + (B + (Y - B) * (i / 25));
if (a) { // draw once two points are set
c.moveTo(a, b);
c.lineTo(x, y)
}
c.strokeStyle = "hsla(" + (U % 360) + ",100%,50%,0.75)"; // draw rainbow hypotrochoid
c.stroke();
a = x; // set previous coord.x
b = y; // set previous coord.y
}
U -= 0.5; // increment hue
A = X; // set original coord.x
B = Y; // set original coord.y
}, 16);
}
j.onkeydown = function(e) { a=b=0; R += 0.05 }
d.onmousemove({pageX:300, pageY:290})
}

</script>
</head>

<body style="margin:0px;padding:0px;width:100%;height:100%;overflow:hidden;">
<canvas id="c"></canvas>
</body>
</html>
...全文
235 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
WODEDAHUA 2015-08-28
  • 打赏
  • 举报
回复
<html> <head> <title>star</title> <script type="text/javascript"> window.onload = function () { d = document.getElementById("c"); c = d.getContext("2d"); W = d.width = window.innerWidth; H = d.height = window.innerHeight; c.fillRect(0, 0, W, H); // resize <canvas> and draw black rect (default) c.globalCompositeOperation = "lighter"; // switch to additive color application c.lineWidth = 0.2; c.lineCap = "round"; var bool = 0, t = 0; // theta d.onmousemove = function (e) { if(window.T) { if(D==0) { D=Math.random()*18; f(1); } clearTimeout(T); } X = e.pageX; // grab mouse pixel coords Y = e.pageY; a=0; // previous coord.x b=0; // previous coord.y R=(e.pageX/W * 999>>0)/999; r=(e.pageY/H * 999>>0)/999; U=e.pageX/H * 360 >>0; D=0; g = 360 * Math.PI / 180; T = setInterval(f = function (e) { // start looping spectrum c.save(); c.globalCompositeOperation = "source-over"; // switch to additive color application if(e!=1) { c.fillStyle = "rgba(0,0,0,0.02)"; c.fillRect(0, 0, W, H); // resize <canvas> and draw black rect (default) } c.restore(); i = 25; while(i --) { c.beginPath(); if(D > 150 || bool) { // decrease diameter if(!bool) { // has hit maximum bool = 1; } if(D < 0.1) { // has hit minimum bool = 0; } R=Math.random(); r=Math.random(); X=W*Math.random() Y=H*Math.random() t = 0; // decrease theta D = 0; // decrease size break } if(!bool) { t += g; // increase theta D += 0.1; // increase size } // create hypotrochoid from current mouse position, and setup variables (see: http://en.wikipedia.org/wiki/Hypotrochoid) //后面加的X和Y是将绘图中心移动到光标位置 x = (R - r) * Math.cos((R-r) / r * t) + D * Math.cos((R-r) / r * t) + X; y = (R - r) * Math.sin((R-r) / r * t) - D * Math.sin((R-r) / r * t) + Y; if (a) { // draw once two points are set c.moveTo(a, b); c.lineTo(x, y) } c.strokeStyle = "hsla(" + (U % 360) + ",100%,50%,0.75)"; // draw rainbow hypotrochoid c.stroke(); a = x; // set previous coord.x b = y; // set previous coord.y U -= 1; // increment hue } }, 60); } window.onkeydown = function(e) { a=b=0; R += 0.05 } d.onmousemove({pageX:300, pageY:290}) } function log(x){console.log(x)} </script> </head> <body style="margin:0px;padding:0px;width:100%;height:100%;overflow:hidden;"> <canvas id="c"></canvas> </body> </html> 这样是不是更有意思些
烟雾中的草堂 2015-08-27
  • 打赏
  • 举报
回复
吊炸天
mfdulang 2015-08-27
  • 打赏
  • 举报
回复
牛B,赞赞赞赞赞赞赞赞
钻石丶青春 2015-08-27
  • 打赏
  • 举报
回复
html5 啊 好炫 里面还用了三角函数 算法 。。。流弊流弊啊。。。
wudizaizai 2015-08-27
  • 打赏
  • 举报
回复
都不鸟这没意思的技术?这玩意中看不中用。。。
wudizaizai 2015-08-27
  • 打赏
  • 举报
回复
我就想知道这能不能改成自动加载的,原点可以自己动任意位置的,比如像meadia player打开音乐主界面炫酷的图线。

87,888

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧