optimize rendering

This commit is contained in:
Kenneth Jao 2017-09-30 21:43:39 -04:00
parent 4ea16e8b91
commit 58a74a95d4

View File

@ -31,12 +31,14 @@ function generateString() {
function generateFrames(frame, string, width, height, rate) { function generateFrames(frame, string, width, height, rate) {
// Rate is in bits per second // Rate is in bits per second
// 30 frames per second // 30 frames per second
var bitsPerSection = Math.ceil(canvas.width/width);
var shift = canvas.width-rate*width*frame/30; var shift = canvas.width-rate*width*frame/30;
var bitsToCalc = Math.ceil(rate*width*frame/(width*30)); var bitsToCalc = Math.ceil(rate*width*frame/(width*30));
var output = []; var output = [];
console.log(shift); console.log(shift);
console.log(bitsToCalc); console.log(bitsToCalc);
for(var i = 0; i < bitsToCalc; i++) { for(var i = bitsToCalc-bitsPerSection; i < bitsToCalc; i++) {
try {
var x = i*width; var x = i*width;
if(parseInt(string[i])) { if(parseInt(string[i])) {
output.push([x+shift, -height+canvas.height/2]); output.push([x+shift, -height+canvas.height/2]);
@ -48,6 +50,7 @@ function generateFrames(frame, string, width, height, rate) {
output.push([x+shift, canvas.height/2]); output.push([x+shift, canvas.height/2]);
output.push([x+width+shift,canvas.height/2]); output.push([x+width+shift,canvas.height/2]);
} }
} catch(err) {}
} }
return output; return output;
@ -74,7 +77,7 @@ function generateFrames(frame, string, width, height, rate) {
} }
return uniq(frame);*/ return uniq(frame);*/
} }
var string = toBinary(getWebsite("https://www.google.com/")); var string = toBinary(getWebsite("https://www.google.com"));
function drawFrame(frame) { function drawFrame(frame) {
ctx.fillRect(0,0, canvas.width, canvas.height); ctx.fillRect(0,0, canvas.width, canvas.height);
@ -100,8 +103,11 @@ ctx.fillStyle = "#000";
ctx.fillRect(0,0, canvas.width, canvas.height); ctx.fillRect(0,0, canvas.width, canvas.height);
function animate(n) { function animate(n) {
if(!animate) return;
drawFrame(n); drawFrame(n);
setTimeout(function() { animate(n+1) }, 100/3); setTimeout(function() { animate(n+1) }, 100/3);
} }
animate(0); animate(0);
var animate = false;