Skip to content

Instantly share code, notes, and snippets.

@rishiosaur
Created December 11, 2015 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rishiosaur/f09cda0d2c944e2c5695 to your computer and use it in GitHub Desktop.
Save rishiosaur/f09cda0d2c944e2c5695 to your computer and use it in GitHub Desktop.
the hexagon
<canvas id = 'canv'></canvas>
var c = document.getElementById('canv'),
$ = c.getContext('2d'),
w = c.width = window.innerWidth,
h = c.height = window.innerHeight,
t = 0, num = 950,
s, a, b,
x, y, _x, _y,
_t = 1 / 60;
var anim = function() {
$.fillStyle = 'hsla(0, 0%, 90%, 12)';
$.fillRect(0, 0, w, h);
for (var i = 0; i < 1; i++) {
x = 0;
$.beginPath();
for (var j = 0; j < num; j++) {
x -= .212 * Math.sin(15);
y = x * Math.sin(i + 2.0 * t + x /20)/0.75;
_x = x * Math.cos(b) - y * Math.sin(b);
_y = x * Math.sin(b) + y * Math.cos(b);
b = (j*6) * Math.PI /17.9;
$.lineTo(w / 2- _x, h / 2 -_y);
}
$.lineWidth = .5;
$.strokeStyle = 'hsla(0,0%,5%,.8)';
$.stroke();
}
t += _t;
window.requestAnimationFrame(anim);
};
anim();
window.addEventListener('resize', function() {
c.width = w = window.innerWidth;
c.height = h = window.innerHeight;
}, false);
body{
width:100%;
overflow:hidden;
margin:0;
background: hsla(0,0%,90%,12);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment