Last active
December 25, 2015 19:09
-
-
Save plugnburn/7025526 to your computer and use it in GitHub Desktop.
Some democode routines (will be updated from time to time)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//bytebeat: beat(pattern,length) | |
beat=function(b,e,a,t){return(a="data")+":audio/wav;base64,UklGRl9fX19XQVZFZm10IBAAAAABAAEAQB8AAEAfAAABAAgA"+btoa(eval("for(t=0;++t<e*8e3;)a+=String.fromCharCode(255&("+b+"))"))} | |
//bytebeat with math: beatm(pattern,length) | |
beatm=function(b,e,a,t){return(a="data")+":audio/wav;base64,UklGRl9fX19XQVZFZm10IBAAAAABAAEAQB8AAEAfAAABAAgA"+btoa(eval("with(Math)for(t=0;++t<e*8e3;)a+=String.fromCharCode(255&("+b+"))"))} | |
//konamicode: konami(callback) | |
konami=function(k,c){onkeyup=function(e){/113302022928$/.test(c+=[e.which-37])&&k()}} | |
//circle gesture detection: circgest(callback[, clockwiseflag]) | |
//clockwiseflag: 1 - counterclockwise, 0 or absent - clockwise | |
circgest=function(f,a,v,i,c,o){c=v="";addEventListener("mousemove",function(e){o&&(i=2*(e.screenX>o.screenX)+(e.screenY>o.screenY),i^c&&(v+=i,c=i),(a?/3201$/:/2310$/).test(v)&&(f(),v=""));o=e},0)} | |
//favtro: favupdate(canvas[, linkelement]) | |
favupdate=function(f,i){i=i||document.querySelector('link[rel*="icon"]');if(!i)with(document)i=createElement("link"),i.rel="icon",head.appendChild(i);i.href=f.toDataURL();return i} | |
//console image output: console.img(url,width,height) | |
console.img=function(c,w,h){console.log("%c ","font-size:1px;padding:"+(h>>1)+"px "+(w>>1)+"px;line-height:"+h+"px;background:url("+c+");background-size:"+w+"px "+h+"px")} | |
//console canvas graphics: console.draw(canvas); | |
console.draw=function(c){console.img(c.toDataURL(),c.width,c.height)} | |
//console asciiart: console.ascii(canvas); - up to 255x255 | |
console.ascii=function(x,e,n,o,s){x=x.getContext("2d").getImageData(n=0,0,e=x.width,x.height).data,s="",o=[];for(e*=4;n in x;n++)s+="%c "+((n+4)%e?"":"\n"),o.push("background-color:rgba("+[x[n],x[++n],x[++n],x[++n]]+")");o.unshift(s);console.log.apply(console,o)} | |
//console random image data URI asciiart: console.imgascii(url) - up to 255x255 | |
console.imgascii=function(u,f,o){f=new Image;f.onload=function(){o=document.createElement("canvas"),o.width=f.width,o.height=f.height,o.getContext("2d").drawImage(f,0,0);console.ascii(o)},f.src=u} | |
//speech synthesis using Web Speech API | |
//usage: speak(phrase[, language]) | |
//if language is omitted, english is used | |
speak=function(s,l,u,v,i){l=l||"english";for(u=new SpeechSynthesisUtterance(s),v=speechSynthesis.getVoices(),i=v.length;i;)if(~v[--i].name.toLowerCase().indexOf(l.toLowerCase())){u.voice=v[i];speechSynthesis.speak(u);break}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment