Jump to content

my console.log demo


rich
 Share

Recommended Posts

rich: I sent you this by mail, but better post this here:

The idea is really cool. Too bad it's so slow to render.

At work your canvasToConsole() method takes at 15-25ms on my i7 @ 3.4Ghz.
The following version takes 12ms max.
 

var canvasToConsole = (function(){  var txt = "";  for (var i = 50*30; i--  {    txt += "%c  ";    if(!(i%50))     txt += "\n";  }  return function()  {    var then = Date.now();    var id = mycanvas.contex.getImageData(0,0,50,30).data;    var bah = [txt];    for (var i = 50*30; i--     bah.push("background: rgb("+id[i*4]+","+id[i*4+1]+","+id[i*4+2]+")");    console.clear();    console.log.apply(console,bah);    console.log(Date.now()-then);  }})();

This also get rid of the blank/whitespace between each row of pixels.

The go() method only needs to process the frame if (Date.now > t)

I haven't been convinced by CODEF yet :\

But at such a low resolution, you can probably use any framework. The

bottleneck is in console.log()

Maybe a slightly lower resolution, and sharper graphics, would improve
the framerate and legibility.Or maybe, but that might be seen as "cheating", go for a simple:
 

var canvasToConsole = function(){  var foo = "width: 150px; height: 90px; background: url("+canvas.toDataURL() +") 150px 90px";  console.clear();  console.log("%c ", foo);} // or anything similar. I haven't tried this, but I'm pretty surethis can work.

Anyways, kudos for exploring new territories!

Link to comment
Share on other sites

Ok brand new version uploaded. This one includes p01's method of getting rid of the white lines! (looks MUCH better now) and I also added RLE so it's faster too as it has to generate a lot smaller logs. Also added option to toggle white/colour background - the white version helps visually. Added new refresh rate, instructions, music toggle.

 

And... I'm done :)

Link to comment
Share on other sites

This one combines your RLE and my single getImageData + rgb colors, thus getting rid of a tons of functions calls.var canvasToConsole3 = function(){  var txt = "";  var prev;  var args = [""];  var lfb = mycanvas.contex.getImageData(0, 0, 50, 30).data;  for (var i = 0, j = 0; i < 1500; i++, j++)  {    if (!(i % 50)) // if(i && !(i % 50)) if don't like to start with a "\n"    	txt += prev = "\n";    var col = "background: rgb(" + [lfb[j++], lfb[j++], lfb[j++]] + ")";    if (col == prev)    {      txt += "  ";    }    else    {      txt += "%c  ";      args.push(col);      prev = col;    }  }  args[0] = txt;  console.clear();  console.log.apply(console, args);};

;)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...