|
| 1 | + |
1 | 2 | <!doctype html>
|
2 | 3 | <html>
|
3 |
| - <head> |
| 4 | + <head> |
4 | 5 | <title>JS1k, 1k demo submission [ID]</title>
|
5 | 6 | <meta charset="utf-8" />
|
6 | 7 | </head>
|
|
111 | 112 | 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.
|
112 | 113 | mapFaces[l][trId].push('hsl('+[ // Using coercion for the ","
|
113 | 114 | 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 |
116 | 116 | : 2 // Blue
|
117 | 117 | ),
|
118 | 118 | 32*( // Saturation
|
119 | 119 | (WATER_LVL<z2)? incCoef*2/zCol // Ground saturation: medium, depending on the incline/height, giving us different kinds of veget.
|
120 | 120 | : zCol // Water saturation: high
|
121 | 121 | )+'%',
|
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 |
127 | 127 | )
|
128 | 128 | ]+'%)');
|
129 | 129 | trId++;
|
|
154 | 154 | a.closePath(),
|
155 | 155 | //a.fill(),
|
156 | 156 | a.stroke()
|
157 |
| - refreshPaint=wantMove? setTimeout(Paint,16) : 0; |
| 157 | + //refreshPaint=wantMove? setTimeout(Paint,16) : 0; |
158 | 158 | };
|
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(); |
162 | 167 | }
|
163 | 168 | b.onmousemove = function(H) { // We tie the mouse position with the camera orientation.
|
164 | 169 | angleYaw = 2*H.clientX/wWidth;
|
|
167 | 172 | b.onmousewheel=b.onwheel = function(H) { // Zooming with the wheel, cross-browser solution
|
168 | 173 | cameraDistance += H.deltaY | -H.wheelDeltaY/40;
|
169 | 174 | }
|
170 |
| -Paint(wantMove^=3); |
| 175 | +Paint(); |
171 | 176 | */
|
172 | 177 | /*
|
173 | 178 | How to minify the demo? Tricks I learned ...
|
|
189 | 194 | - 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());"
|
190 | 195 | - Adapt your equations to the context to avoid useless operations or steps / Look at the whole picture
|
191 | 196 | */
|
192 |
| - |
193 | 197 | /*
|
194 | 198 | // Real code as implemented:
|
195 |
| -d=[],g=[], D=[], r=R=21,Y=.6 |
| 199 | +d=[],g=[], D=[], r=R=20,Y=.6 |
196 | 200 |
|
197 | 201 | // 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 ... |
199 | 203 |
|
200 | 204 | for(;l<8;){
|
201 | 205 | i=p = 2*o-1,d[++l] = [], g[l]=[], h /= 2
|
|
222 | 226 | q+r,
|
223 | 227 | y=d[l][u+o+1],
|
224 | 228 | 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)]+'%)']); |
226 | 230 | }
|
227 | 231 | }
|
228 | 232 | e=function(H,S,L){
|
|
247 | 251 | a.lineTo(d[l][8], d[l][7]), // Smaller than closePath once jsCrushed
|
248 | 252 | //a.fill(),
|
249 | 253 | a.stroke()
|
250 |
| - o=T?setTimeout(e,16):0 |
| 254 | + //o=T?setTimeout(e,16):0 |
251 | 255 | };
|
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()} |
253 | 259 | b.onmousemove=function(H,S,L){Z=2*H.clientX/h,Y=2*H.clientY/r}
|
254 | 260 | //b.onmousewheel=function(H,S,L){
|
255 | 261 | // R+=H.wheelDelta/99} // Not supported by FF, alas...
|
256 | 262 | //b.onkeydown=function(H,S,L){
|
257 | 263 | // R+=(H.which==40)-(H.which==38)} // ... so we use the arrows instead. Less elegant, and 6B heavier.
|
258 | 264 | b.onmousewheel=b.onwheel=function(H,S,L){
|
259 | 265 | 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 | + |
261 | 270 |
|
| 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() |
262 | 278 | */
|
263 | 279 |
|
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() |
266 | 286 | */
|
267 | 287 |
|
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(_) |
270 | 290 |
|
271 | 291 | </script>
|
272 | 292 | </body>
|
|
0 commit comments