e=document,f=e.getElementById("c"),g=f.width=640,j=f.height=128,k=[],l=[];z=[];w=[];z[1]=w[1]=w[2]=z[3]=0;z[0]=w[0]=z[2]=w[3]=255;m=0;for(i=2048;i;){k[--i]=16*Math.sin(i*3.14/128);l[i]=256*(1+Math.pow(Math.cos(i*3.14/1024),3))}n=f.getContext("2d");n.fillRect(0,0,g,j);n.fillStyle="#fff";o=n.getImageData(0,0,g,j),p=n.getImageData(0,0,g,j),q=o.data,r=p.data;e.body.style.background="#000";function u(d,h,s,t){h+=64;for(y=0;y<j-h>>1;){q[d]=(d>>6)+(y++>>4)&1?s:t;d+=g<<2}for(;y++<j+h>>1;){q[d]=255;d+=g<<2}for(;y<j;){q[d]=(d>>6)+(y++>>4)&1?s:t;d+=g<<2}}function v(d,h){oy=0;oi=(j<<8)/d;for(y=0;y++<d;){oy+=oi;os=x+(oy>>8)*g<<2;r[od]=z[h]^q[os]*d>>7;r[od+1]=w[h]^q[os+1]*d>>7;r[od+2]=w[h]^q[os+2]*d>>7;od+=g<<2}}setInterval(function(){m+=4;for(x=g;x;){a=m+--x*4&511;b=m-x*2&511;c=-m*2-x&511;u(x<<2,k[a]+k[b]-k[c],16,8);u((x<<2)+1,k[c]+k[a]-k[b],16,4);u((x<<2)+2,k[b]+k[c]-k[a],64,32);d=l[m*2+l[m-x/2&2047]&2047]&511;od=x<<2;v(d&127,d>>7);v(j-(d&127),(d>>7)-1&3)}n.putImageData(p,0,0);n.fillText("Rubfun/Yoyofr",550,116)},20);
var doc = document;
var canvas = doc.getElementById("c");
var width = canvas.width = 640;//innerWidth;
var height = canvas.height = 128;//innerHeight;
var mySinR=[],mySin=[];
xg=[];xr=[];
//xg[0]=255;xr[0]=255;
//xg[1]=0;xr[1]=0;
//xg[2]=255;xr[2]=0;
//xg[3]=0;xr[3]=255;
xg[1]=xr[1]=xr[2]=xg[3]=0;
xg[0]=xr[0]=xg[2]=xr[3]=255;
var cpt=0;
//Init the sin lookup arrays for waves fx & rubber fx
i=2048;while(i) {
mySinR[--i]=16*Math.sin(i*3.14/128);
mySin[i]=256*(1+Math.pow(Math.cos(i*3.14/1024),3));
}
//get canvas context, clear BG (assume fillStyle is #000) and then prepare for white font drawing.
var ctx = canvas.getContext("2d");
ctx.fillRect(0, 0, width, height);
ctx.fillStyle = '#fff';
// get 2 rendering image : iamge1 for waves, image2 for rubber
var image1 = ctx.getImageData(0, 0, width, height);
var image2 = ctx.getImageData(0, 0, width, height);
var data1 = image1.data;
var data2 = image2.data;
// Black html background
doc.body.style.background = "#000";
// Draw a vertical line for a wave
function vlineR(ofs,ysize,colBG1,colBG2) {
ysize+=64;
y=0;while (y<(height-ysize)>>1) {
data1[ofs] = (((ofs>>6)+(y++>>4))&1?colBG1:colBG2);
ofs += width<<2;
}
while (y++<(height+ysize)>>1){
data1[ofs] = 255;
ofs += width<<2;
}
while (y<height) {
data1[ofs] = (((ofs>>6)+(y++>>4))&1?colBG1:colBG2);
ofs += width<<2;
}
}
// Zoom function for rubber
function t(ys,xf) {
oy = 0;
oi=(height<<8)/ys;
y=0;while (y++<ys) {
oy+=oi;
os=(x + (oy>>8)*width)<<2;
data2[od] = xg[xf]^data1[os]*ys>>7;
data2[od+1] = xr[xf]^data1[os+1]*ys>>7;
data2[od+2] = xr[xf]^data1[os+2]*ys>>7;
od+=width<<2;
}
}
// Draw a vertical line for the rubber fx
function rubberY(ysize1) {
od = x<<2;
t(ysize1&127,(ysize1>>7));
t(height-(ysize1&127),((ysize1>>7)-1)&3);
}
function f() {
cpt+=4;
x=width;
while (x) {
//Waves are composed by adding multiple sinus with different 'speed'
a=( cpt + --x*4 ) & 511;
b= ( cpt - x*2 ) & 511;
c= ( -cpt*2 - x ) & 511;
vlineR(x<<2,mySinR[a ]+mySinR[b]-mySinR[c],16,8);
vlineR((x<<2)+1,mySinR[c]+mySinR[a]-mySinR[ b],16,4);
vlineR((x<<2)+2,mySinR[b]+mySinR[c]-mySinR[a],64,32);
rubberY(mySin[(cpt*2+mySin[(cpt - x/2)&2047])&2047]&511);
}
ctx.putImageData(image2, 0, 0);
ctx.fillText("Rubber fun/Yoyofr", 9, 9);
}
setInterval(f, 20);