Skip to content

Commit 6f89780

Browse files
<Admin> Cleaning drafts.
1 parent 5eba65a commit 6f89780

9 files changed

+84
-2089
lines changed

js1k-2013-loom-drag-1017B.html

-298
This file was deleted.

js1k-2013-loom-drag-greener-contrast.html

-288
This file was deleted.

js1k-2013-loom-drag-greener.html

-291
This file was deleted.

js1k-2013-loom-drag-melting.html

-297
This file was deleted.

js1k-2013-loom-drag-mild.html

-290
This file was deleted.

js1k-2013-loom-drag-rand-spheri.html

-297
This file was deleted.

js1k-2013-loom-drag.html

-298
This file was deleted.

js1k-2013-loom.html

+44-24
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
12
<!doctype html>
23
<html>
3-
<head>
4+
<head>
45
<title>JS1k, 1k demo submission [ID]</title>
56
<meta charset="utf-8" />
67
</head>
@@ -111,19 +112,18 @@
111112
zCol = z3 - incCoef; // Useful value to make the boundary snow/vegetation less obvious/more random, and more importantly to somehow reduce the melting-point for poorly-lighted faces. Or how to cheaply simulate the illumination effect on snow.
112113
mapFaces[l][trId].push('hsl('+[ // Using coercion for the ","
113114
99*( // Hue
114-
(SNOW_LVL_INC<zCol)? 1 // Yellowish-greenish hue (snow-white with the good lightness, or muddy-alpine-green otherwise. Fine enough.)
115-
: (WATER_LVL<z2)? 7/z2 // Greenish
115+
(WATER_LVL<z2)? 6/z2 // Greenish
116116
: 2 // Blue
117117
),
118118
32*( // Saturation
119119
(WATER_LVL<z2)? incCoef*2/zCol // Ground saturation: medium, depending on the incline/height, giving us different kinds of veget.
120120
: zCol // Water saturation: high
121121
)+'%',
122-
44*( // Lightness
123-
(SNOW_LVL_INC<zCol)? incCoef// Bright snow
124-
: (BEACH_LVL<z2)? incCoef/4 // Normal vegetation
125-
: (WATER_LVL<z2)? incCoef // Bright sand
126-
: 1-Math.random()/5 // Water with random waves
122+
30*( // Lightness
123+
(SNOW_LVL_INC<zCol)? incCoef/.6 // Bright snow
124+
: (BEACH_LVL<z2)? incCoef*incCoef/7 // Normal vegetation
125+
: (WATER_LVL<z2)? incCoef/.6 // Bright sand
126+
: 2-Math.random()/3 // Water with random waves
127127
)
128128
]+'%)');
129129
trId++;
@@ -154,11 +154,16 @@
154154
a.closePath(),
155155
//a.fill(),
156156
a.stroke()
157-
refreshPaint=wantMove? setTimeout(Paint,16) : 0;
157+
//refreshPaint=wantMove? setTimeout(Paint,16) : 0;
158158
};
159-
b.onclick = function() { // We change the view mode on click.
160-
clearTimeout(refreshPaint);
161-
Paint(wantMove^=3);
159+
// Drag to move around:
160+
b.onmousedown=function(){
161+
wantMove=3;
162+
clearInterval(refreshPaint); refreshPaint=setInterval(Paint,16);
163+
} // We have to clear the Interval in the case the user release the click out of the body.
164+
b.onmouseup=function(){
165+
wantMove=0;
166+
clearInterval(refreshPaint); Paint();
162167
}
163168
b.onmousemove = function(H) { // We tie the mouse position with the camera orientation.
164169
angleYaw = 2*H.clientX/wWidth;
@@ -167,7 +172,7 @@
167172
b.onmousewheel=b.onwheel = function(H) { // Zooming with the wheel, cross-browser solution
168173
cameraDistance += H.deltaY | -H.wheelDeltaY/40;
169174
}
170-
Paint(wantMove^=3);
175+
Paint();
171176
*/
172177
/*
173178
How to minify the demo? Tricks I learned ...
@@ -189,13 +194,12 @@
189194
- Save 2 bytes by changing the jsCrush bootstrap: replace "for(Y=0;$='CHAR'[Y++];)with(_.split($))_=join(pop());" by "for(Y in $='CHAR')with(_.split($[Y]))_=join(pop());"
190195
- Adapt your equations to the context to avoid useless operations or steps / Look at the whole picture
191196
*/
192-
193197
/*
194198
// Real code as implemented:
195-
d=[],g=[], D=[], r=R=21,Y=.6
199+
d=[],g=[], D=[], r=R=20,Y=.6
196200
197201
// Generating the landscape with various levels of details :
198-
g[T=Z=l=0]=[o=2,4,9,h=8]//.sort(function(){return .5-Math.random()}) // Initial description of our map : a hole, a bump, and some stuff between ...
202+
g[T=l=0]=[o=2,4,Z=9,h=8]//.sort(function(){return .5-Math.random()}) // Initial description of our map : a hole, a bump, and some stuff between ...
199203
200204
for(;l<8;){
201205
i=p = 2*o-1,d[++l] = [], g[l]=[], h /= 2
@@ -222,7 +226,7 @@
222226
q+r,
223227
y=d[l][u+o+1],
224228
x=2+(z-y)/r,
225-
'hsl('+[99*(7<(y-=x)?1:6<z?7/z:2),32*(6<z?x*2/y:y)+'%',44*(7<y?x:6.04<z?x/4:6<z?x:1-Math.random()/5)]+'%)']);
229+
'hsl('+[99*(7<(y-=x)?1:6<z?7/z:2),32*(6<z?x*2/y:y)+'%',44*(7<y?x:6.05<z?x/4:6<z?x:1-Math.random()/5)]+'%)']);
226230
}
227231
}
228232
e=function(H,S,L){
@@ -247,26 +251,42 @@
247251
a.lineTo(d[l][8], d[l][7]), // Smaller than closePath once jsCrushed
248252
//a.fill(),
249253
a.stroke()
250-
o=T?setTimeout(e,16):0
254+
//o=T?setTimeout(e,16):0
251255
};
252-
b.onclick=function(H,S,L){clearTimeout(o),e(T^=3)}
256+
//b.onclick=function(H,S,L){clearTimeout(o),e(T^=3)}
257+
b.onmousedown=function(H,S,L){T=3,o=setInterval(e,16)}
258+
b.onmouseup=function(H,S,L){T=0,clearTimeout(o),e()}
253259
b.onmousemove=function(H,S,L){Z=2*H.clientX/h,Y=2*H.clientY/r}
254260
//b.onmousewheel=function(H,S,L){
255261
// R+=H.wheelDelta/99} // Not supported by FF, alas...
256262
//b.onkeydown=function(H,S,L){
257263
// R+=(H.which==40)-(H.which==38)} // ... so we use the arrows instead. Less elegant, and 6B heavier.
258264
b.onmousewheel=b.onwheel=function(H,S,L){
259265
R+=H.deltaY|-H.wheelDeltaY/40} // Cross-browser solution, but to heavy ... --Update: Now we can afford it! \o/
260-
e(T^=3)
266+
e()
267+
*/
268+
269+
261270

271+
/* Minimized + Spherical Movement + Rand for hue + No more "b." + better pattern for click handlers + d[l]->d + Z+3 + Trigo infine
272+
273+
d=[];g=[];R=r=22;Y=.6;g[l=0]=[o=2,5,Z=9,T=h=8];for(D=[];8>l;){i=p=2*o-1;d=[];h/=2;for(g[++l]=[];i--;)for(j=p;j--;v=g[l-1][u=o*(i/2|0)+j/2|0],w=i*p+j,g[l][w]=d[w]=(i%2?j%2?(v*2+d[w+p]+d[w+1])/4:(v+g[l-1][u+o])/2:j%2?(v+g[l-1][u+1])/2:v)+h*(Y-Math.random()),d[w]=6>d[w]?6:d[w]);o=i=p--;i--;r/=2;for(D[l]=[];i--;)for(j=p;j--;)for(k=2;k--;D[l][Z++]=[i*r-11,j*r-11,d[u=o*i+j],(i+k)*r-11,(j+1-k)*r-11,z=d[u+1+k*p],(i+1)*r-11,(j+1)*r-11,y=d[u+o+1],y-=x=2+(z-y)/r,"hsla("+[32*(6<z?R/z-Math.random():6),32*(6<z?x*2/y:y)+"%",32*(6<y-1?x/Y:6.05<z?x*x/7:6<z?x:2-Math.random()/3)]+"%,"]);}e=function(f,n){a.fillRect(0,0,h=c.width=innerWidth-18,r=c.height=innerHeight-21);m=-Math.cos(Z);w=-Math.sin(Z);o=Math.cos(Y);x=Math.sin(Y);g=[];h/=2;for(l in D[T]){g[l]=[];for(j=9;j;v=D[T][l][--j]-R*o,u=D[T][l][--j]-R*m,t=D[T][l][--j]-R*w,g[l].push(p=o*v+(k=m*u+w*t)*x,(v*x-o*k)/p*r+r,(w*u-m*t)/p*h+h));g[l][9]=D[T][l][10]}p=-l*p/40;g.sort(function(f,n){return f[3]-n[3]});for(l in g)a.strokeStyle=g[l][9]+l/p+")",a.beginPath(),a.moveTo(g[l][8],g[l][7]),a.lineTo(g[l][2],g[l][1]),a.lineTo(g[l][5],g[l][4]),a.lineTo(g[l][8],g[l][7]),a.stroke()};onmousedown=function(f,n){clearInterval(i),T=5,i=setInterval(e,9)};onmouseup=function(f,n){clearInterval(i),T=8,e()};onmousemove=function(f,n){Z=f.clientX/h;Y=f.clientY/r};onmousewheel=onwheel=function(f,n){R+=f.deltaY|-f.wheelDeltaY/80};e()
274+
*/
275+
276+
/* Melting Snow Version:
277+
d=[];g=[];R=r=21;Y=.6;g[l=0]=[o=2,5,Z=9,T=h=8];for(D=[];8>l;){i=p=2*o-1;d[++l]=[];h/=2;for(g[l]=[];i--;)for(j=p;j--;v=g[l-1][u=o*(i/2|0)+j/2|0],w=i*p+j,g[l][w]=d[l][w]=(i%2?j%2?(v*2+d[l][w+p]+d[l][w+1])/4:(v+g[l-1][u+o])/2:j%2?(v+g[l-1][u+1])/2:v)+h*(Y-Math.random()),d[l][w]=6>d[l][w]?6:d[l][w]);o=i=p--;i--;r/=2;for(D[l]=[];i--;)for(j=p;j--;){for(k=2;k--;D[l][Z++]=[i*r-9,j*r-9,d[l][u=o*i+j],(i+k)*r-9,(j+1-k)*r-9,d[l][u+1+k*p],(i+1)*r-9,(j+1)*r-9,d[l][u+o+1]]);}}e=function(f,n){a.fillRect(0,0,h=c.width=innerWidth-18,r=c.height=innerHeight-21);m=-Math.cos(Z);w=-Math.sin(Z);o=Math.cos(Y);x=Math.sin(Y);d=[];h/=2;for(l in D[T]){d[l]=[];for(j=9;j;v=D[T][l][--j]-R*o,u=D[T][l][--j]-R*m,t=D[T][l][--j]-R*w,d[l].push(p=o*v+(k=m*u+w*t)*x,(v*x-o*k)/p*r+r,(w*u-m*t)/p*h+h));v=D[T][l][5];u=D[T][l][8];u-=t=2+(v-u)*T;d[l][9]="hsl("+[32*(6<v?22/v:6),32*(6<v?t*2/u:u)+"%",32*(6<u-Math.sin(R/9)?t/Y:6.05<v?t*t/7:6<v?t:2-Math.random()/3)]+"%)"}d.sort(function(f,n){return f[3]-n[3]});for(l in d)a.strokeStyle=d[l][9],a.beginPath(),a.moveTo(d[l][8],d[l][7]),a.lineTo(d[l][2],d[l][1]),a.lineTo(d[l][5],d[l][4]),a.lineTo(d[l][8],d[l][7]),a.stroke()};b.onmousedown=function(f,n){T=5,clearInterval(i),i=setInterval(e,16)};b.onmouseup=function(f,n){clearInterval(i),e(T=8)};b.onmousemove=function(f,n){Z=2*f.clientX/h;Y=2*f.clientY/r};b.onmousewheel=b.onwheel=function(f,n){R+=f.deltaY|-f.wheelDeltaY/40};e()
262278
*/
263279

264-
/* Ready to be jsCrushed (1332B to 1025B):
265-
d=[];g=[];r=21,R=25;Y=.6;g[T=Z=l=0]=[o=2,4,9,h=8];for(D=[];8>l;){i=p=2*o-1;d[++l]=[];h/=2;for(g[l]=[];i--;)for(j=p;j--;v=g[l-1][u=o*(i/2|0)+j/2|0],w=i*p+j,g[l][w]=d[l][w]=(i%2?j%2?(v*2+d[l][w+p]+d[l][w+1])/4:(v+g[l-1][u+o])/2:j%2?(v+g[l-1][u+1])/2:v)+h*(Y-Math.random()),d[l][w]=6>d[l][w]?6:d[l][w]);o=i=p--;i--;r/=2;for(D[l]=[];i--;)for(j=p;j--;){;for(k=2;k--;D[l][Z++]=[m=i*r-9,q=j*r-9,d[l][u=o*i+j],(i+k)*r-9,(j+1-k)*r-9,z=d[l][u+1+k*p],m+r,q+r,y=d[l][u+o+1],x=2+(z-y)/r,"hsl("+[99*(7<(y-=x)?1:6<z?7/z:2),32*(6<z?x*2/y:y)+"%",40*(7<y?x:6.04<z?x/3:6<z?x:1-Math.random()/5)]+"%)"]);}}e=function(f,n){a.fillRect(0,0,h=c.width=innerWidth-17,r=c.height=innerHeight-21);m=-Math.cos(Z);w=-Math.sin(Z);o=Math.cos(Y);x=Math.sin(Y);d=[];h/=2;for(l in D[8-T]){d[l]=[];for(j=9;j;v=D[8-T][l][--j]-R*o,u=D[8-T][l][--j]-R*m,t=D[8-T][l][--j]-R*w,d[l].push(z=o*v+(k=m*u+w*t)*x,(v*x-o*k)/z*r+r,(w*u-m*t)/z*h+h));d[l][9]=D[8-T][l][10]}d.sort(function(f,n){return f[3]-n[3]});for(l in d)a.strokeStyle=d[l][9],a.beginPath(),a.moveTo(d[l][8],d[l][7]),a.lineTo(d[l][5],d[l][4]),a.lineTo(d[l][2],d[l][1]),a.lineTo(d[l][8],d[l][7]),a.stroke();o=T?setTimeout(e,16):0};b.onclick=function(f,n){clearTimeout(o),e(T^=3)};b.onmousemove=function(f,n){Z=2*f.clientX/h;Y=2*f.clientY/r};b.onmousewheel=b.onwheel=function(f,n){R+=f.deltaY|-f.wheelDeltaY/40};e(T^=3)
280+
/* Mild Version:
281+
d=[];g=[];R=r=22;Y=.6;g[T=l=0]=[o=2,4,Z=8,h=7];for(D=[];8>l;){i=p=2*o-1;d[++l]=[];h/=2;for(g[l]=[];i--;)for(j=p;j--;v=g[l-1][u=o*(i/2|0)+j/2|0],w=i*p+j,g[l][w]=d[l][w]=(i%2?j%2?(v*2+d[l][w+p]+d[l][w+1])/4:(v+g[l-1][u+o])/2:j%2?(v+g[l-1][u+1])/2:v)+h*(Y-Math.random()),d[l][w]=5>d[l][w]?5:d[l][w]);o=i=p--;i--;r/=2;for(D[l]=[];i--;)for(j=p;j--;){for(k=2;k--;D[l][Z++]=[i*r-11,j*r-11,d[l][u=o*i+j],(i+k)*r-11,(j+1-k)*r-11,z=d[l][u+1+k*p],(i+1)*r-11,(j+1)*r-11,y=d[l][u+o+1],y-=x=1+(z-y)/r*.7,"hsl("+[99*(5<z?6/z:2),55*(5<z?x/y*2:y)+"%",85*(6<y?x:5.04<z?x/3:5<z?x:.6-Math.random()/8)]+"%)"]);}}e=function(f,n){a.fillRect(0,0,h=c.width=innerWidth-18,r=c.height=innerHeight-21);m=-Math.cos(Z);w=-Math.sin(Z);o=Math.cos(Y);x=Math.sin(Y);d=[];h/=2;for(l in D[8-T]){d[l]=[];for(j=9;j;v=D[8-T][l][--j]-R*o,u=D[8-T][l][--j]-R*m,t=D[8-T][l][--j]-R*w,d[l].push(z=o*v+(k=m*u+w*t)*x,(v*x-o*k)/z*r+r,(w*u-m*t)/z*h+h));d[l][9]=D[8-T][l][10]}d.sort(function(f,n){return f[3]-n[3]});for(l in d)a.strokeStyle=d[l][9],a.beginPath(),a.moveTo(d[l][8],d[l][7]),a.lineTo(d[l][5],d[l][4]),a.lineTo(d[l][2],d[l][1]),a.lineTo(d[l][8],d[l][7]),a.stroke()};b.onmousedown=function(f,n){T=3,clearInterval(i),i=setInterval(e,16)};b.onmouseup=function(f,n){T=0,clearInterval(i),e()};b.onmousemove=function(f,n){Z=2*f.clientX/h;Y=2*f.clientY/r};b.onmousewheel=b.onwheel=function(f,n){R+=f.deltaY|-f.wheelDeltaY/40};e()
282+
*/
283+
/* High Contrast Version:
284+
d=[];g=[];R=r=22;Y=.6;g[T=l=0]=[o=2,4,Z=8,h=7];for(D=[];8>l;){i=p=2*o-1;d[++l]=[];h/=2;for(g[l]=[];i--;)for(j=p;j--;v=g[l-1][u=o*(i/2|0)+j/2|0],w=i*p+j,g[l][w]=d[l][w]=(i%2?j%2?(v*2+d[l][w+p]+d[l][w+1])/4:(v+g[l-1][u+o])/2:j%2?(v+g[l-1][u+1])/2:v)+h*(Y-Math.random()),d[l][w]=5>d[l][w]?5:d[l][w]);o=i=p--;i--;r/=2;for(D[l]=[];i--;)for(j=p;j--;){for(k=2;k--;D[l][Z++]=[i*r-11,j*r-11,d[l][u=o*i+j],(i+k)*r-11,(j+1-k)*r-11,z=d[l][u+1+k*p],(i+1)*r-11,(j+1)*r-11,y=d[l][u+o+1],x=1+(z-y)/r,"hsl("+[99*(6<(y-=x)?1:5<z?7/z:2),64*(5<z?x*2/y:y)+"%",75*(6<y?x:5.04<z?x/3:5<z?x:Y-Math.random()/9)]+"%)"]);}}e=function(f,n){a.fillRect(0,0,h=c.width=innerWidth-18,r=c.height=innerHeight-21);m=-Math.cos(Z);w=-Math.sin(Z);o=Math.cos(Y);x=Math.sin(Y);d=[];h/=2;for(l in D[8-T]){d[l]=[];for(j=9;j;v=D[8-T][l][--j]-R*o,u=D[8-T][l][--j]-R*m,t=D[8-T][l][--j]-R*w,d[l].push(z=o*v+(k=m*u+w*t)*x,(v*x-o*k)/z*r+r,(w*u-m*t)/z*h+h));d[l][9]=D[8-T][l][10]}d.sort(function(f,n){return f[3]-n[3]});
285+
for(l in d)a.strokeStyle=d[l][9],a.beginPath(),a.moveTo(d[l][8],d[l][7]),a.lineTo(d[l][5],d[l][4]),a.lineTo(d[l][2],d[l][1]),a.lineTo(d[l][8],d[l][7]),a.stroke()};b.onmousedown=function(f,n){T=3,clearInterval(i),i=setInterval(e,16)};b.onmouseup=function(f,n){T=0,clearInterval(i),e()};b.onmousemove=function(f,n){Z=2*f.clientX/h;Y=2*f.clientY/r};b.onmousewheel=b.onwheel=function(f,n){R+=f.deltaY|-f.wheelDeltaY/40};e()
266286
*/
267287

268-
/* jsCrushed (1023B):*/
269-
_='dgr1,R5;Y=.6;g[T=Z=l=0K[o,4,9,h=8];D8>l;Li=p*o-1;d[++l]hgv==o&iU)+jUw=i*p+j,gwK=(i%2?#*2+ w+p]+ w@]4:(v++oV#+@Vv)+h&Y!=6>?6:Bi=pirDL;k;kDZ++K[m=iq=j u=o*i+j(i+k)(j@-k)z= u@+k*pmCqCy= u+o@x+(z-yr,"hsl("+[99&7<(y-=x)?1:67/z:2!32&6x*2/y:y)+"%",40&7<y?x:6.04x/3:6x:1/5)]+"%)"]}}eNAfillRect(0,0,h=c.widOEWidO-17,r=c.hFEHF-21m=-GZw=-_ZBGYx=_Ydh`Ldj=9;j;vo,um,tw,d.push(z=o*v+(k=m*u+w*t)*x,(v*x-o*kz*rC(w*u-m*tz*h+h) 9K10]}d.sort(return f[3]-n[3]}`d)Style= 9AbegPaO(!AmovI8Q75Q42Q18Q7]!(BT?sete,16):0clickNclearo!$moveNZX/h;YY/r$=b.onNR+=f.dJ|-f.DJ/40};[function(f,nL=--j]-R*]!AlIfor(=[];MaO.i)j=p;j dg[l-1][u*r-9,=2D[8-T]};b.on);-random()*f.client],--;wheelinAstrokeTimeout( w]<z?[l]/;e(T^=3))/!),#j%2?(v$mouse&*(@+1Aa.Bo=C+r,E=nerFeightGcos(IeTo( JeltaYK]=L){N=OthQ U/2|0V]2:_s(`l ';for(Y in $='`_VUQONLKJIGFECBA@&$#! ')with(_.split($[Y]))_=join(pop());eval(_)
288+
/* jsCrushed (1024B):*/
289+
_='d g R=r2;Y=.6;=0[o,5,Z=9,T=h=8];D 8>l;){i=p*o@;d hg[++v=CQ_)+j_Aw=i*p+j,$wQ%2?&*2++p]+]!4:(v++o`&+`v)+h*(Y#6>]?6:]o=i=pirD[)k;kDZ++[ijECi+jAQ+kO-k)z=E+k*pAQO)y=E+oAy-=x+(z-y!r,"hsla("+[z?R/z:6#F*2/y:y)+"%",y@?x/Y:6.05<F*x/7:6<F:2/3)]+"%,"]}e^BfillRect(0,0,h=c.widUKWidU@8,r=c.hGKHG-21m=-LZw=-~Zo=LYx=~Yg hq){] j=9;j;vo,um,tw,].push(pCv+(k=m*u+w*t)*x,(v*x-o*k!p*r+r,(w*u-m*t!p*h+h)$910]}p=-l*p/40;g.sort(return f[3]-n[3]}qg)Style=$9]+l/p+")",BbegPaU(#BmovN87215487]#Vdown5,i=sete,9)up8,eVmove^ZX/h;YY/r=on^R+=f.dJ|-f.DJ/80};eVfunction(f,n){[l][-randomV]#BlN*r@1,for(};onmouse=--j]-R* =[];^cleari#T=MaU.l] i)j=p;j@][ud[w32*(6<A$);--;wheel/;Interval(=f.clientinBstroke+1g[lD[T]=2]=!)/#),$g&j%2?(v@-1A],Ba.C=o*Ed[uFz?xGeightJeltaYK=nerLcos(NeTo($O)(jQ(iUthV()^=_/2|0`]!2:ql ~s(';for(Y in $='~q`_^VUQONLKJGFECBA@&$#! ')with(_.split($[Y]))_=join(pop());eval(_)
270290

271291
</script>
272292
</body>

0 commit comments

Comments
 (0)