html http://gbrlgrct.com/gists/a48a2a7ddb6b38d52194/starry.html
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了html http://gbrlgrct.com/gists/a48a2a7ddb6b38d52194/starry.html相关的知识,希望对你有一定的参考价值。
<body style="background:black;margin:0"></body>
<script>
var SPACEW = document.body.clientWidth;
var SPACEH = document.body.clientHeight;
var canvas = document.createElement('canvas');
canvas.width = SPACEW;
canvas.height = SPACEH;
document.body.appendChild(canvas);
var ctx = canvas.getContext('2d');
var rad = SPACEH / 2;
var deg = 0.17;
var ang = 0;
var clean = true;
ctx.translate(SPACEW/2, SPACEH/2);
function draw(t) {
var ang_ = ang + Math.PI - 2*deg;
var ix = rad * Math.cos(ang);
var iy = rad * Math.sin(ang);
var ox = rad * Math.cos(ang_);
var oy = rad * Math.sin(ang_);
var c = Math.floor(360 * (t % 5000) / 5000);
ctx.strokeStyle = 'hsl('+c+', 50%, 50%)';
ctx.lineWidth = 10;
ctx.beginPath();
ctx.moveTo(ix, iy);
ctx.lineTo(ox, oy);
ctx.stroke();
if (clean) {
ctx.fillStyle = 'rgba(0, 0, 0, 0.05)';
ctx.fillRect(-SPACEW/2, -SPACEH/2, SPACEW, SPACEH);
}
ang = ang_;
}
function loop(t) {
draw(t);
requestAnimationFrame(loop);
}
loop(0);
canvas.addEventListener('mousemove', function (e) {
deg = Math.PI * e.offsetY / SPACEH;
rad = 20 + (SPACEW / 2 - 20) * e.offsetX / SPACEW;
});
canvas.addEventListener('click', function (e) {
clean = !clean;
});
</script>
以上是关于html http://gbrlgrct.com/gists/a48a2a7ddb6b38d52194/starry.html的主要内容,如果未能解决你的问题,请参考以下文章
html http://gbrlgrct.com/gists/0ec9f597e2c9b37fc868/pi.html
html http://gbrlgrct.com/gists/08640e24c907cc627eca/webgl-mandelbrot.html
html http://gbrlgrct.com/gists/a48a2a7ddb6b38d52194/starry.html
html http://gbrlgrct.com/gists/deec0c0c12e63a94515b/burn.html
html http://gbrlgrct.com/gists/53e9405a69ad5922c3ed/mandelbrot.html
html http://gbrlgrct.com/gists/cc5ea4bf19838a41e527/cardiod.html