Skip to content

Instantly share code, notes, and snippets.

@vilmibm
Created February 3, 2017 01:38
Show Gist options
  • Save vilmibm/07da7aba96e5be164447f91c37beaa32 to your computer and use it in GitHub Desktop.
Save vilmibm/07da7aba96e5be164447f91c37beaa32 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-color: rgb(10,10,10);
}
#header {
z-index: 1;
position:absolute;
width: 100%;
height:20%;
left: 0;
top: 0;
opacity:.5;
}
</style>
</head>
<body>
<img id="header" src="http://neongrid.space/img/neongrid_nobg.png">
<script>
LINE_THICKNESS = 1;
MAX_STEPS = 10000;
MAX_GAP = 90;
MIN_GAP = 10;
function mkcanvas() {
var canv = document.createElement('canvas');
var header = document.querySelector('#header');
canv.width = header.width;
canv.height = header.height;
console.log(canv);
console.log(header.height);
return canv;
}
function draw_lines(canv, ctx, gap) {
ctx.clearRect(0,0,canv.width,canv.height)
ctx.fillStyle = 'rgb(200,0,200)';
for (x = gap; x < canv.width; x += gap) {
ctx.fillRect(x, 0, LINE_THICKNESS, canv.height);
}
for (y = gap; y < canv.height; y += gap) {
ctx.fillRect(0, y, canv.width, LINE_THICKNESS);
}
}
function animate(canv) {
var ctx = canv.getContext('2d');
var frame = 0;
var line_gap = MIN_GAP;
var growth = 1;
function do_step() {
// do stuff
if (frame == MAX_STEPS) {
return;
}
frame += 1
draw_lines(canv, ctx, line_gap);
if (line_gap == MAX_GAP) {
growth = -1;
} else if (line_gap == MIN_GAP) {
growth = 1;
}
line_gap += growth;
window.requestAnimationFrame(do_step);
}
window.requestAnimationFrame(do_step);
}
function go() {
var body = document.querySelector('body');
var canv = mkcanvas();
body.appendChild(canv);
animate(canv);
}
go();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment