in reply to Re: Bear is driving?
in thread Bear is driving?
use GD; $i = new GD::Image( 153, 153, ); $i->colorAllocate( 200, 200, 200 );
sub l { $p = new GD::Polygon; $x=shift; $y=shift; $p->addPt( ( $x += shift ), ( $y += shift ) ) while $#_; $i->filledPolygon( $p, shift ); }
sub d { l @_, 0, 0, 20, -10, 20, 10, -20, 10, $i->colorAllocate( 153, 15 +3, 153, ); l @_, 20, 10, 20, -10, 0, 20, -20, 10, $i->colorAllocate( 20, 0, + 0 ); }
sub a { d @_; l @_, 0, 0, 0, 20, 20, 10, 0, -20, $i->colorAllocate( 20, 153, 153 +, ); }
These basically draw boxes in an order so they stack properly.a("73","73"); a("43","88"); a("13","103"); a("13","73"); a("13","43"); a("13","13"); a("43","28"); a("73","43"); a("103","58");
This is added so that the top and right of the first box overlay all the others - creating the impossible perspective.d("73","73");
open FH, ">o.png"; binmode FH; print FH $i->png
we can then call them like this:$$_ = ord(shift) - 20 for qw.x y.;
which then becomes this:a"]","]"; a"?","l"; a"!","{"; a"!","]"; a"!","?"; a"!","!"; a"?","0"; a"]","?"; a"{","N"; d"]","]"
ie take two chars out of the string, and replace them with a"$1","$2";, then match the first call and use it to call d();$_ = "]]?l!{!]!?!!?0]?{N"; s#(.)(.)#a"$1","$2";\n#g; /".+;/; $_ .= "d$&"; eval;
eval will run the calls, drawing the boxes.
To obfuscate, and save space i then did a form of huffman encoding, where repeated strings are replaced with a single letter, to do this the bulk of the program was but in $_, (using q^..^;) and then run through this:
for each of those strings in the main block, substitute the letter (starting at A (chr 65) ) with the corresponding string, so A is $i-> B is colorAllocat( etc.for$r(qw.$i-> colorAllocate( Polygon shift) l@_, KK); GD 10, I sub 153, 20 new.){$l=chr 65+$c++;s#$l#$r#g}
finally $_ (all the code) is eval'd
Before posting i run it through my obfu formatter (which i call perlmess - the opposite of perltidy :) ), which simply reformats it as lines of 72 chars. (i also use it in development of these things as it tells me how many chars i'm at, and how many over 4 lines i am etc etc).
Considered by teamster_jr: I was thinking of moving this to mediations as an explanation of obfuscation. is it worth it?
Unconsidered by planetscape: keep votes prevailed (keep:15 edit:3 reap:0)
|
|---|