I see all competitors are making demos nicer and nicer, but my demo was just bump map of blurred letters :)
a="o,f,A,C,H,X,Y,Z,b,c,d,e,m,n,x,y,W,v,tvar p=document.body.children[0],wwidth=218,hheigh14g=w*h,qgetCont2d'q.fon'100px sans-seriStyle='#ffTjs1k',21e2HWH-%p*4]/25;4;t--WW(-w]+w]+&+-&)/4||0;H=W}XYZa=w+&-H||b=&-w]||x=b+y=b-4),X-x/t,Yy/t,Z-2/t;setIntervalq.clearRect(w,hv;W=vxcos(oy!z=.5+.2*Math.!*.3z*zx/y/z/o.05;{f6*X+y*Y-z*Z;f>0)%4*p 7*f;%4*p+3]7}a*xb*yc*zm691:1;n=y9w:w;d=e6=y=f=0;ACbb;b=a;am;m=n;nf=1}p=-1;y>-11A[++p]6;Cy;xm;(db))d-=xn;(ec))e-=--y}c=p;ddp=0;a=d;do H[a]<C)a]<Ca}elsea]>=Cf)%t*=4 *=.5}f)}q.putImageData(v,0)},33)})(0)";for(b in c="9>0?-7=2556=x&1]%W[!sin(oext('a<=p.+=+a,.data;=){1e4=t;0,t=f';q.fill(function(pp)while(if();abs(0|H[p&a>0&&a<g)&&H[ ]=W[t+1]=W[t+2]tsqrt(x*x+y*y+=[];=q.getImageData(0,0,w,h)[p]{while((f=++p<c&&(a=d+A[p])%w&=Math.=-1;while(g>++".split(""))a=a.replace(RegExp(c[b][0],"g"),c[b].slice(1));eval(a)
YT0iEm8sZixBLEMsSCxYLFksWiwaYixjLGQsZSxtLG4seCx5LFcsdix0DHZhciBwPWRvY3VtZW50LmJvZHkuY2hpbGRyZW5bMF0sdx13aWR0aD0yMTgsaB1oZWlnaBQxNBVnPXcqaCxxHWdldENvbnQfMmQnDnEuZm9uFCcxMDBweCBzYW5zLXNlcmkTU3R5bGU9JyNmZhNUH2pzMWsnLDIVMWUyDkgHVwYZEUgYLSVwKjRdLzI1OxQ0OxB0LS0MVwcRVxgoBC13XSsbd10rGyYrBC0mKS80fHwwO0g9V31YB1kHWgcRYT0bdysmLUgFfHwVY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demo was just bump map of blurred letters :)
After two days of work i have made realistic bump map/height map of blurred letters with per pixel raytraced shadow %) It based on Bresenham line algorithm modified for 3D space and collision detection with height map. Unfortunately it works very slow. I recommend lastest chrome to see demo. It minified manually %) because all js compressor give random names to variables, but cool http://www.iteral.com/jscrush/ requires a lot of patterns for best compression ratio. As the result - i compressed 8k to 1k with a lot of hacks. For example `maxHeight` was precomputed in compressed version, Bresenham algorithm was simplified, etc.
*/
(function($G)
{
//document.write('<style>body{background:#000}</style>');
var outText = 'js1k'
, canvas = document.body.children[0]//document.getElementById('c')
, p = canvas
, h = canvas.height = 140
, font = '100px sans-serif'
, strGetImageData = 'getImageData'
, Float32Array = $G.Float32Array || $G.WebGLFloatArray || Array
, S32Array = $G.Int32Array || $G.WebGLIntArray || Array
, canvasCtx = canvas.getContext('2d')
;
canvasCtx.font = font;
var w = canvasCtx.measureText(outText).width + 40
, wh = w*h
;
//canvasCtx = null;
p.width = w;
//canvasCtx = a.getContext('2d');
canvasCtx.font = font;
canvasCtx.fillStyle = '#FFF';
canvasCtx.textBaseline = 'top';
canvasCtx.fillText(outText, 20, 20);
//console.log(w, h, wh);
var heightBitmapCopy = [].slice.call(canvasCtx[strGetImageData](0, 0, w, h).data, 0);
var heightBitmap = new Float32Array(wh);
var p = -1; while(++p < wh) heightBitmap[p] = -heightBitmapCopy[p*4]/25;
var i = 4; while(i--)
{
var heightBitmapCopy = new Float32Array(wh);
var p = -1; while(++p < wh)
{
heightBitmapCopy[p] = (heightBitmap[p - w] + heightBitmap[p + w] + heightBitmap[p + 1] + heightBitmap[p - 1])/4 || 0;
//ps2[p] = (heightBitmap[p - w] + heightBitmap[p] + heightBitmap[p + w] + heightBitmap[p + 1] + heightBitmap[p - 1])/5;
}
heightBitmap = heightBitmapCopy;
}
var maxHeight = 0;
var p = -1; while(++p < wh)
{
if(heightBitmap[p] < maxHeight)
maxHeight = heightBitmap[p];
}
//console.log('maxHeight = ', maxHeight);
var bumpNormalsX = new Float32Array(wh)
, bumpNormalsY = new Float32Array(wh)
, bumpNormalsZ = new Float32Array(wh)
;
p = -1; while(++p < wh)
{
var z11subz00 = heightBitmap[p + w + 1] - heightBitmap[p] || 0
, z10subz01 = heightBitmap[p + 1] - heightBitmap[p + w] || 0
, x = z10subz01 + z11subz00
, y = z10subz01 - z11subz00
, z = -2
, len = Math.sqrt(x*x + y*y + z*z)
;
bumpNormalsX[p] = -x/len;
bumpNormalsY[p] = y/len;
bumpNormalsZ[p] = z/len;
}
//console.log(heightBitmap);
var dir = Math.PI*1/2
, lastTime = new Date
, shiftsLen = ~~Math.sqrt(w*w + h*h) + 1
, shiftsXL = new S32Array(shiftsLen)
, shiftsYL = new S32Array(shiftsLen)
, shiftsZL = new S32Array(shiftsLen)
;
canvasCtx.fillStyle = '#000';
//(function()
setInterval(function()
{
var now = +new Date
, fps = 1000/(now - lastTime)
;
document.title = ~~fps + ' fps';
lastTime = now;
canvasCtx.fillRect(0, 0, w, h);
//canvasCtx.clearRect(0, 0, w, h);
var bitmapWrapper = canvasCtx[strGetImageData](0, 0, w, h)
, bitmap = bitmapWrapper.data
, lightX = Math.cos(dir)
, lightY = Math.sin(dir)
, lightZ = -0.5 - 0.2*Math.sin(dir*0.3) // MUST be 0 < _ < -Math.sin(Math.PI/4)
, lightLen = Math.sqrt(lightX*lightX + lightY*lightY + lightZ*lightZ)
, temp
, whc = wh
, wc = w
, hc = h
;
lightX /= lightLen;
lightY /= lightLen;
lightZ /= lightLen;
dir += 0.05;
var p = -1; while(++p < whc)
{
var dot = lightX*bumpNormalsX[p] + lightY*bumpNormalsY[p] + lightZ*bumpNormalsZ[p];
if(dot >= 0)
{
bitmap[temp = 4*p] = bitmap[temp + 1] = bitmap[temp + 2] = 255*dot;
//bitmap[temp + 3] = 255;
}
}
//return;
var dx = Math.abs(lightX*10000|0)
, dy = Math.abs(lightY*10000|0)
, dz = Math.abs(lightZ*10000|0)
, xyError = 0
, xzError = 0
, x = 0
, y = 0
, z = 0
, incX = (lightX < 0) ? 1 : -1
, incY = (lightY < 0) ? 1 : -1
, shiftsX = shiftsXL
, shiftsY = shiftsYL
, shiftsZ = shiftsZL
, isSwapXYShifts
;
if(dx < dy)
{
var temp = dy;
dy = dx;
dx = temp;
isSwapXYShifts = 1;
var temp = incX;
incX = incY;
incY = temp;
}
//console.log(lightX, lightY, lightZ);
//console.log(dx, dy, dz);
//console.log(!!isSwapXYShifts);
//return;
var nwc = -wc
, nhc = -hc
, maxHeightC = maxHeight
;
var p = -1; while(
//nwc < x && x < wc &&
//nhc < y && y < hc &&
z > maxHeightC
)
{
++p;
shiftsX[p] = x;
shiftsY[p] = y;
shiftsZ[p] = z;
x += incX;
/*
if(isSwapXYShifts)
bitmap[(~~((wc/2 - y) + (hc/2 - x)*w)*4) + 2] = 255;
else
bitmap[(~~((wc/2 - x) + (hc/2 - y)*w)*4) + 2] = 255;
*/
//console.log(x, y, z);
if((xyError += dy) > dx)
{
xyError -= dx;
y += incY;
}
if((xzError += dz) > dx)
{
xzError -= dx;
--z;
}
}
if(isSwapXYShifts)
{
var temp = shiftsY;
shiftsY = shiftsX;
shiftsX = temp;
}
//console.log(shiftsX)
//console.log(shiftsY)
//console.log(shiftsZ)
//return;
var shiftsLen = p;
//var k = 10000;
var heightBitmapC = heightBitmap;
//console.log(shiftsLen);
var y = -1; while(++y < h)
{
var x = -1; while(++x < w)
{
var v//isInside = heightBitmapC[x + y*w] < 0
, i = 0
, notFinal
, sx = x
, sy = y
, p = x + y*w
;
//if(isInside)
// bitmap[4*(p) + 1] = 255
//var k = 0;
do
{
if(heightBitmapC[sx + sy*w] < shiftsZ[i])
//if(isInside)
{
while(
(notFinal = (
++i < shiftsLen &&
0 <= (sx = x + shiftsX[i]) && sx < wc &&
0 <= (sy = y + shiftsY[i]) && sy < hc
)) &&
heightBitmapC[sx + sy*w] < shiftsZ[i]
)
;//k > 0 && (bitmap[4*(sx + sy*w) + 1] = 255);
//console.log(x, y, sx, sy);
//break;
p = sx + sy*w;
}
else
{
while(
(notFinal = (
++i < shiftsLen &&
0 <= (sx = x + shiftsX[i]) && sx < wc &&
0 <= (sy = y + shiftsY[i]) && sy < hc
)) &&
heightBitmapC[sx + sy*w] >= shiftsZ[i]
)
;//k > 0 && (bitmap[4*(sx + sy*w) + 1] = 255);
if(notFinal)
{
//if(k > 2)
//if(k-- > 0 && k < 10)
// console.log(i, notFinal, sx, sy, heightBitmap[sx + sy*w], shiftsZ[i]);
//p *= 4;
/*
bitmap[4*p] = 255;
bitmap[4*p + 1] = 0;
bitmap[4*p + 2] = 0;
*/
bitmap[p *= 4] *= 0.5;
bitmap[p + 1] *= 0.5;
bitmap[p + 2] *= 0.5;
//bitmap[p + 3] = 255;
//bitmap[p] *= 0.5;
}
//break;
}
//k++;
//isInside = !isInside;
}
while(notFinal);
//if(isInside && k > 1)
// bitmap[4*p] = 255;
//if(k > 1)
//console.log(x, y, k);
}
}
canvasCtx.putImageData(bitmapWrapper, 0, 0);
//heightBitmap = bid = null;
},33);
//})();
})(this);