This is a hanjie puzzle(christmas edition). The goal is to cross stitch the image described by the numbers, each of which stands for a block of same-color stitches. The space between the blocks is fil…
function B(x,y,w,h){w?a.fillRect(x,y,w,h):a.fillStyle='#'+'15ffb1ea9f1311000036ffd4fbaf45221000'.substr(x*3,3);return B}P=[0,0,x=21760,21,320,80,x,21,0,0,x,21,x+64,85,y=43600,362,41616,418,y+64,426,60052,1450,y+4,1386,22272,53,24560,1021,32240,991,32752,1023];B(V=113,U=T=0,c.width=x=c.height=369,O=112)(0,V,O,x);for(W=[N=[r=2]];r--;)for(y=S=16;y--;){R=[];v=z=0;for(x=S;x--;N[x+y*S]=4)s=r?x:y,(i=W[y+x*S]=P[(r?y:x)*2|s>>3]>>s%8*2&3)?i-v?R.push(k=[v=i,1]):k[1]++:v=0;for(;x=R[z];a.fillText(x[1],r?s-8:t,r?7+t:s))B(x[0]),s=O-z++*S-6,t=O+y*S+5}c.onmousedown=document.onmouseup=c.onmousemove=q=function(e,f){if(!f||!B(5)(s=V+e*S,t=97+f*S,S,S)(10)(s+4,t,8,S)(4)(s,t+4,S,9)){x=e.clientX-O>>4;y=e.clientY-O>>4;f=e.type&&e.type[7];h=f=='w'&!e.button;Q=0;for(i in N)Q|=N[i]-W[i];z=(x|y)<0;B(T=Q?z&h?++T%4:T:5)(0,0,O,O)(T+6)(0,0,69,O);U=U?f:h;if(Q&&U&&!z)for(N[x+y*S]=k=e.shiftKey?4:T,q(x,y+1),i=13;i--;)for(l=2;l--;)k-4&&a.beginPath(B(i<9?k+6:k))&a.fill(a.arc(O+x*S+(l?i:12-i)+3,t+i+2,2,0,7,0))}};for(q(m=S);m--;)for(n=17;--n;)q(m,n)
ZnVuY3Rpb24gQih4LHksdyxoKXt3P2EuZmlsbFJlY3QoeCx5LHcsaCk6YS5maWxsU3R5bGU9JyMnKycxNWZmYjFlYTlmMTMxMTAwMDAzNmZmZDRmYmFmNDUyMjEwMDAnLnN1YnN0cih4KjMsMyk7cmV0dXJuIEJ9UD1bMCwwLH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ZpbGwoYS5hcmMoTyt4KlMrKGw/aToxMi1pKSszLHQraSsyLDIsMCw3LDApKX19O2ZvcihxKG09Uyk7bS0tOylmb3Iobj0xNzstLW47KXEobSxuKQ==
// Christmas Cross Stitch Hanjie by @veubeke, artwork by @UlrikeErdmann
// draws a rectangle or sets a color
function rect(x,y,w,h) {
w ? a.fillRect(x,y,w,h)
: a.fillStyle = '#'+'15ffb1ea9f1311000036ffd4fbaf45221000'.substr(x*3,3);
return rect
}
// image, can you guess it from the source? ;)
img = [0,0,x=21760,21,320,80,x,21,0,0,x,21,x+64,85,y=43600,362,41616,418,y+64,
426,60052,1450,y+4,1386,22272,53,24560,1021,32240,991,32752,1023];
// draw UI, initialize board
rect(off2=113,active=color=0,c.width=x=c.height=369,offset=112)(0,off2,offset,x);
for(img2=[board=[r=2]]; r--;)
for(y=size=16; y--;) {
// measure blocks
numbers = [];
v = z = 0;
for(x=size; x--; board[x+y*size]=4)
s = r?x:y,
// save 'decoded' image for easier access
(i=img2[y+x*size]=img[(r?y:x)*2|s>>3]>>s%8*2&3)
? i-v ? numbers.push(k=[v=i,1]) : k[1]++
: v = 0;
// print block lengths
for(;x=numbers[z]; a.fillText(x[1],r?s-8:t,r?7+t:s))
rect(x[0]),
s = offset-z++*size-6,
t = offset+y*size+5
}
c.onmousedown = document.onmouseup = c.onmousemove = q = function(e,f) {
// draws fabric
if(!f||!rect(5)(s=off2+e*size,t=97+f*size,size,size)(10)(s+4,t,8,size)(4)(s,t+4,size,9)) {
// get event info
x = e.clientX-offset >> 4;
y = e.clientY-offset >> 4;
f = e.type && e.type[7];
// make sure that the other buttons don't work
h = f=='w' & !e.button;
// end check
incomplete = 0;
for(i in board)
incomplete |= board[i]-img2[i];
// change and show current color
z = (x|y)<0;
rect(color=incomplete?z&h?++color%4:color:5)(0,0,offset,offset)(color+6)(0,0,69,offset);
active = active ? f : h;
// update board, draw fabric and cross
if(incomplete && active && !z)
for(board[x+y*size]=k=e.shiftKey?4:color,q(x,y+1),i=13; i--;)
for(l=2; l--;)
k-4 && a.beginPath(rect(i<9?k+6:k)) & a.fill(a.arc(offset+x*size+(l?i:12-i)+3,t+i+2,2,0,7,0))
}
};
// show color, draw fabric
for(q(m=size); m--;)
for(n=17; --n;)
q(m,n)