Unconed's failrail : http://jsbin.com/edepor/1/edit
This is a minification attempt by me. See gist history for a few in-between commits. End result is 1452 bytes by jscrush (http://www.iteral.com/jscrush/), that's where I leave it.
I've not even tested this code, I don't care myself if it doesn't even run anymore (but would be pretty sweet if it did! ;)).
The dollar signs allow you to find usages of a variable. The dollar sign itself is not used in the program, so you can remove all of them for "production" minification. As long as they're there, you can figure out where a variable is used (use case sensitive search) very easy this way.
Things you might want to try:
- Remove variable declarations where possible (I think you can gain a lot by this, but you're at the mercy of the compression gods here)
- Try to use certain variables more frequent. This should please the compression gods
- Try to rewrite certain expressions so that they look more like each other. For example, the functions are all declared in the same manner. This allows the compression to pick up that long
=function(A,B,C,D){returnstring and replace it with one single character. Or that's the theory anyways. - Write a custom packer. Tweak the source code to only use as few bytes as possible, build a hufman en/decoder that's specifically tuned to revive that compression. I think you can get away with a lot that way, especially if you tinker with the code to reduce the number of used bytes.
- Break the code down even more. Make many tiny functions. Keep in mind, the
func...part (should!) only take one byte! So the overhead is one byte, plus closing bracket, plus assignment, plus call. Might allow you to tweak repetitive patterns even further.
Anyways. Have fun. I did. Thanks steven, for the demo :) It's awesome! Keep sending in your js1k's, I'm loving every one of 'em!
with(Math){
var $b=document.body
var $c=document.getElementsByTagName('canvas')[0]
var $a=$c.getContext('2d')
function $f($F){return function($A,$B,$C,$D){return $D=$D||[],[$F($A[0],$B[0],$C,$D[0]),$F($A[1],$B[1],$C,$D[1]),$F($A[2],$B[2],$C,$D[2])]}}
var
$d=function($A,$B,$C,$D){return $A-$B},
$e=function($A,$B,$C,$D){return $A+($B-$A)*$C},
$g=function($A,$B,$C,$D){return $A+$B*$C},
$h=function($A,$B,$C,$D){return sqrt($A[0]*$A[0]+$A[1]*$A[1]+$A[2]*$A[2])},
$i=function($A,$B,$C,$D){return $j(A,$h($A)+.0001)},
$j=function($A,$B,$C,$D){return [$A[0]/$B,$A[1]/$B,$A[2]/$B]},
$k=function($A,$B,$C,$D){return [$A[1]*$B[2]-$A[2]*$B[1],$A[2]*$B[0]-$A[0]*$B[2],$A[0]*$B[1]-$A[1]*$B[0]]},
$l=function($A,$B,$C,$D){return ($B+$D)/2},
$m=function($A,$B,$C,$D){return $i($_($k([0,1,0],$C=$d($A,$B)),300*($k($C,$d($B,$D))[1]*max(0,$B[1]-$U))))},
$_=function($A,$B,$C,$D){return a[1]-=b,a},
$n=function($A,$B,$C,$D){return $r=!$r,$A-=$z[0],$B-=$z[1],$C-=$z[2],$D=$A*$Z[6]+$B*$Z[7]+$C*$Z[8],$D>.0001?($r&&$a.beginPath(),($r|$q)&&$a[$r?'moveTo':'lineTo'](($A*$Z[0]+$B*$Z[1]+$C*$Z[2])/$D,($A*$Z[3]+$B*$Z[4]+$C*$Z[5]+.02)/$D),$a.stroke(),$q=1):$q=0},
$o=function($A,$B,$C,$D){$t=[];$C=$s[$Q];while($C--)for($B=$s[$C],$D=0;$B&&$D<1;$D+=.0667)$t.push($e($A,$B,$D));$C=150;while($C--)$t=$p($t,$l);$u=$p($t,$m);$v=$p($t,$d);$t.reverse()},
$p=function($A,$B,$C,$D){$C=[];$A[-1]=$A[0];$A[$D=$A[$Q]]=$A[$D-1];while($D--)$C.push($B($A[$D-1],$A[$D],0,$A[$D+1]));$A.pop();return $C}
$c.onmousemove=function($A,$B,$C,$D){return $B=$s[$s[$Q]-1],$C=$A.offsetY/$x-.5,$V+=$A.shiftKey?$C-$X:0,$B[1]=$Y=min(0,$V*2.5),$X=$C,$C-=$V-1,$B[0]=1.6*($A.offsetX/$w-.5)*$y/$C,$B[2]=3/($C+.1)-3,$o()}
$c.onclick=function($A,$B,$C,$D){return $s.push([0,$Y,0]),$U=min($U,$Y)}
$c.ondblclick=function($A,$B,$C,$D){return $s[$Q]-=2,$c.onmousemove=0,$W=true,$o()}
$d=$f($d)
$e=$f($e)
$g=$f($g)
$l=$f($l)
var
$q,
$r,
$s=[[0,0,0]],
$t,
$u,
$v,
$Q='length',
$w=$c.width=innerWidth,
$x=$c.height=innerHeight,
$y=$w/$x,
$z=[0,-1.3,-1.6],
$Z=[1,0,0,0,.707,-.707,0,.707,.707],
$W,
$X,
$Y,
$V=0,
$U= 0,
$T=0,
$S=0,
$R='strokeStyle'
$a.scale($w/$y,$x)
$a.translate($y/2,.5)
$a.lineWidth=2/$x
$o()
setInterval(function($A,$B,$C,$D){$A=$t[$Q]-1
$a.clearRect(-$y,-1,$y*2,2)
if($W)$z=$e($t[$C=floor($T)],$t[$C+1],$D=$T-$C),$B=$i($e($v[$C],$v[$C+1],$D)),$C=$h($v[$C]),$D=$i($e($u[$C],$u[$C+1],$D)),$Z=$D.concat($k($B,$D),$B),$S=max(.0015,$S+$B[1]*.0004),$T=($T+$S/$C)%($A-1)
else {$a[$R]='#ddd'
$B=$A&~1
while(($B-=2)>0)$n($t[$B][0],0,$t[$B][2]),$n.apply(0,$t[$B])}
$a[$R]='#38f';
$B=$A&~1
var $C=.01
while(--$B>1){$A=3
while($A--)$n.apply(0,$g($t[$B],$u[$B],$C)),$A==1&&($C=-$C),$n.apply(0,$g($t[$B-1],$u[$B-1],$C))}},33)}