Skip to content
Browse files

minor xmas tweaks

  • Loading branch information...
1 parent 5e61c45 commit 58a56a2dcb03f0578f87236a2de97d037765dc03 @cowboy committed
Showing with 17 additions and 16 deletions.
  1. +1 −1 organ1k-xmas.html
  2. +15 −14 organ1k-xmas.js
  3. +1 −1 organ1k-xmas.min.js
View
2 organ1k-xmas.html
@@ -29,6 +29,6 @@
var b = document.body;
var a = c.getContext('2d');
</script>
- <script src="organ1k-xmas.min.js"></script>
+ <script src="organ1k-xmas.js"></script>
</body>
</html>
View
29 organ1k-xmas.js
@@ -12,7 +12,7 @@
// in parens. Since I don't care about the return value of the function, it
// can still be invoked immediately, just as long as I prefix it with a unary
// operator, like ! ~ + -.
-with(Math)with(a)!function(txt,colors){
+with(Math)with(a)!function(char_scale,txt,colors){
/*
// Passing a single var into the closure nets us two bytes of savings, but
// since any more than that doesn't help, it's not worth doing for (cough)
@@ -95,6 +95,10 @@ with(Math)with(a)!function(txt,colors){
*/
+ // Now that I'm using `with(Math)`, the preceding comments are no longer
+ // relevant... but they're still interesting!
+ rnd = random,
+
// Due to the way the math and circle drawing is done (and the
// aforementioned three_sixty variable), it saves bytes to have a
// reference to pi * 2 instead of just pi.
@@ -105,7 +109,6 @@ with(Math)with(a)!function(txt,colors){
blip_current = 0,
math_mode = 0,
last_n = 0,
- txt_idx = 0,
/*
// Because assignment operators have right-to-left associativity, it can
@@ -164,7 +167,7 @@ with(Math)with(a)!function(txt,colors){
// num_items = 32,
// num_colors = colors.length,
- theta = random(
+ theta = rnd(
/*
// While assigning a variable or invoking a function inside the parens
@@ -197,7 +200,7 @@ with(Math)with(a)!function(txt,colors){
) * three_sixty,
- dir = random(
+ dir = rnd(
// Allow user to "take control" by moving the mouse.
onmousemove = function(event){
@@ -225,7 +228,7 @@ with(Math)with(a)!function(txt,colors){
// browsers, as well as IE9).
// Change the mode, as long as it's not the last mode changed.
- while ( last_n == ~~( tmp = random( tmp2 = random() ) * 6 ) );
+ while ( last_n == ~~( tmp = rnd( tmp2 = rnd() ) * 5 ) );
last_n = ~~tmp;
/*
@@ -254,17 +257,15 @@ with(Math)with(a)!function(txt,colors){
// Change the rotational velocity.
: tmp < 4 ? cycle_speed = tmp2 * 8 + 1
// Change the "tightness".
- : tmp < 5 ? delay_speed = tmp2 * 3 + 1
- // Cycle text chars.
- : txt_idx++
+ : delay_speed = tmp2 * 3 + 2
}
// Set these values in each iteration to allow the window to be resized.
width = c.width = innerWidth;
height = c.height = innerHeight;
max_radius = min( origin_x = width / 2, origin_y = height / 2 );
- blip_scale = max_radius / three_sixty * 6; // 400;
- max_radius -= 4 * blip_scale;
+ blip_scale = max_radius / three_sixty * 4; // 400;
+ max_radius -= 6 * blip_scale;
// Only override mouse movement generated x/y if mouse hasn't moved within
// the last second.
@@ -349,15 +350,15 @@ with(Math)with(a)!function(txt,colors){
// Draw the blip.
fillStyle = '#' + tmp.c;
- font = tmp2 * blip_scale + 'px Arial';
+ font = tmp2 * blip_scale * char_scale + 'px Arial';
textAlign = 'center';
textBaseline = 'middle';
- fillText( txt[ ( i + txt_idx ) % 5 /* txt.length */ ], origin_x + tmp.x, origin_y + tmp.y );
+ fillText( txt[ i % txt.length ], origin_x + tmp.x, origin_y + tmp.y );
}
}, thirty_two /* 1e3 / fps */ )
-// Since YUI compressor adds a trailing ; to its output and wraps with blocks in {},
+// Since YUI compressor adds a trailing ; to its output and wraps `with` blocks in {},
// this is adjusted in minify.sh post-minification.
-}( '\u2605\u2736\u2606\u2739\u2735', 'f001a001700140010f010a010701040'.split(1) )
+}( 1.5, '\u2605\u2736\u2606\u2739\u2735\u2727\u2738', 'f001a001700140010f010a010701040'.split(1) )
View
2 organ1k-xmas.min.js
@@ -1 +1 @@
-with(Math)with(a)!function(r,k){var z,u,D,B,m,j,E=b.style,l=32,G=360,w=PI*2,n=w/G,q=0,d=0,A=0,i=0,s=0,f=E.margin=0,F=2,p=2,o=3,C=6,e=l,t=[],g=[],h=random(E.overflow="hidden")*G,v=random(onmousemove=function(x){e=0;m=x.clientX-D;j=x.clientY-B})<.5?1:-1;setInterval(function(I,x,H,y,J){if(!(++q%l)){while(i==~~(y=random(J=random())*6));i=~~y;y<.4?v=-v:y<2?f++:y<3?A=J*7:y<4?F=J*8+1:y<5?p=J*3+1:s++}z=c.width=innerWidth;u=c.height=innerHeight;I=min(D=z/2,B=u/2);x=I/G*6;I-=4*x;if(++e>l){if(A<1){h-=F*v*4;m=sin(h*n)*I;j=cos(h*n)*I}else{h-=F*v*2;y=abs(m=sin(h*n)*I);m=y*cos(J=atan2(0,m)+h*n/A);j=y*sin(J)}}for(H=0;H<l;){y=t[H]=t[H]||{x:0,y:0};J=t[H-1];y.x=H?y.x+(J.x-y.x)/p:m;y.y=H++?y.y+(J.y-y.y)/p:j}for(H=0;y=t[H*4];){g[d++%G]={s:1,d:1,c:k[(f+H++)%8],x:y.x,y:y.y}}fillRect(H=0,0,z,u);while(y=g[H++]){J=y.s+=y.d;y.d=J>C?-1:J<o?1:y.d;fillStyle="#"+y.c;font=J*x+"px Arial";textAlign="center";textBaseline="middle";fillText(r[(H+s)%5],D+y.x,B+y.y)}},l)}("\u2605\u2736\u2606\u2739\u2735","f001a001700140010f010a010701040".split(1))
+with(Math)with(a)!function(e,t,m){var A,v,E,C,o,l,F=b.style,n=32,H=360,k=random,z=PI*2,p=z/H,s=0,d=0,B=0,j=0,g=F.margin=0,G=2,r=2,q=3,D=6,f=n,u=[],h=[],i=k(F.overflow="hidden")*H,w=k(onmousemove=function(x){f=0;o=x.clientX-E;l=x.clientY-C})<.5?1:-1;setInterval(function(J,x,I,y,K){if(!(++s%n)){while(j==~~(y=k(K=k())*5));j=~~y;y<.4?w=-w:y<2?g++:y<3?B=K*7:y<4?G=K*8+1:r=K*3+2}A=c.width=innerWidth;v=c.height=innerHeight;J=min(E=A/2,C=v/2);x=J/H*4;J-=5*x;if(++f>n){if(B<1){i-=G*w*4;o=sin(i*p)*J;l=cos(i*p)*J}else{i-=G*w*2;y=abs(o=sin(i*p)*J);o=y*cos(K=atan2(0,o)+i*p/B);l=y*sin(K)}}for(I=0;I<n;){y=u[I]=u[I]||{x:0,y:0};K=u[I-1];y.x=I?y.x+(K.x-y.x)/r:o;y.y=I++?y.y+(K.y-y.y)/r:l}for(I=0;y=u[I*4];){h[d++%H]={s:1,d:1,c:m[(g+I++)%8],x:y.x,y:y.y}}fillRect(I=0,0,A,v);while(y=h[I++]){K=y.s+=y.d;y.d=K>D?-1:K<q?1:y.d;fillStyle="#"+y.c;font=K*x*e+"px Arial";textAlign="center";textBaseline="middle";fillText(t[I%t.length],E+y.x,C+y.y)}},n)}(1.5,"\u2605\u2736\u2606\u2739\u2735\u2727\u2738","f001a001700140010f010a010701040".split(1))

0 comments on commit 58a56a2

Please sign in to comment.
Something went wrong with that request. Please try again.