From 58a74a95d45634cabc49cfd5c01f0975c8dfa28f Mon Sep 17 00:00:00 2001 From: Kenneth Jao Date: Sat, 30 Sep 2017 21:43:39 -0400 Subject: [PATCH] optimize rendering --- gyrio/index.js | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/gyrio/index.js b/gyrio/index.js index 3b02d78..8f6d3bb 100644 --- a/gyrio/index.js +++ b/gyrio/index.js @@ -31,23 +31,26 @@ function generateString() { function generateFrames(frame, string, width, height, rate) { // Rate is in bits per second // 30 frames per second + var bitsPerSection = Math.ceil(canvas.width/width); var shift = canvas.width-rate*width*frame/30; var bitsToCalc = Math.ceil(rate*width*frame/(width*30)); var output = []; console.log(shift); console.log(bitsToCalc); - for(var i = 0; i < bitsToCalc; i++) { - var x = i*width; - if(parseInt(string[i])) { - output.push([x+shift, -height+canvas.height/2]); - output.push([x+width+shift, -height+canvas.height/2]); - if(string[i-1] === 0) { - output.push([x+width+shift, canvas.height/2]); + for(var i = bitsToCalc-bitsPerSection; i < bitsToCalc; i++) { + try { + var x = i*width; + if(parseInt(string[i])) { + output.push([x+shift, -height+canvas.height/2]); + output.push([x+width+shift, -height+canvas.height/2]); + if(string[i-1] === 0) { + output.push([x+width+shift, canvas.height/2]); + } + } else { + output.push([x+shift, canvas.height/2]); + output.push([x+width+shift,canvas.height/2]); } - } else { - output.push([x+shift, canvas.height/2]); - output.push([x+width+shift,canvas.height/2]); - } + } catch(err) {} } return output; @@ -74,7 +77,7 @@ function generateFrames(frame, string, width, height, rate) { } return uniq(frame);*/ } -var string = toBinary(getWebsite("https://www.google.com/")); +var string = toBinary(getWebsite("https://www.google.com")); function drawFrame(frame) { ctx.fillRect(0,0, canvas.width, canvas.height); @@ -100,8 +103,11 @@ ctx.fillStyle = "#000"; ctx.fillRect(0,0, canvas.width, canvas.height); function animate(n) { + if(!animate) return; drawFrame(n); setTimeout(function() { animate(n+1) }, 100/3); } animate(0); + +var animate = false;