Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Balls! Pt 4

by teamster_jr (Curate)
on Jun 13, 2006 at 13:50 UTC ( [id://555043]=obfuscated: print w/replies, xml ) Need Help??

part 4 of an occasional series: (1,2,3)
$_='map($ ..=pack("C",--$ _),@_=unpack"C*", q^pqfo!g -#?p/cnq#<qsjou!g!qb dl#b3W:y31Dy4D2 127#-CN-29429-1-2189-5 1-251-241-63539:- 1-29311-366-279<%v>qbd l#y29311#<%q>5+bubo3 )2-2*<gps)1//31111*|%s >%`+%q02911<nbq!|%i>fy q))%s,%`0:*0:*0:<%y>)2 0)%i,20%i**+dpt%s<%z>) 20)%i,20%i**+tjo%s<w fd)%v-jou)81+)2,%y,%z* ,251+)21,jou)26,91 +%i++30)2,%i++3*,51+)% z.%y****-9*>)%q 03,%s*&)3+%q*?%q@3;2 ~1//26~qs jou!g%v^),eval$.' ;s#\s##g;eval

this generates a file called o.bmp, and shares some code with 3, but hopefully i've fixed the problems people were having (ie wrapping). if anyone has any problems please let me know and i'll try and fix it!
enjoy.
alex Update I've added a deconstruction as a reply

Replies are listed 'Best First'.
Re: Balls! Pt 4
by teamster_jr (Curate) on Jun 14, 2006 at 10:25 UTC
    commented and cleaned up code is in the spoiler:
    #!/usr/bin/perl open f, ">o.bmp"; # print the bmp file header, and the colour pallette # (3 entries : 0=black, 1 = blue, 2 = dark blue); print f pack "a2V9x20C2x2C1016", BM, 18318, 0, 1078, 40, 140, 130, 524 +289, 0, 18200, 168, 0, 98; # make a string of null bytes for the image; $image = pack "x18200"; # PIE! $pi = 4 * atan2( 1, 1 ); # rotate around the origin 0 to 2000 degrees # (*10 so we do it in increments of .1 degrees) for $angle ( 0 .. 20000 ) { # convert to radians and change it to .1 degrees # (1 rad = degrees * pi / 180) $radians = $angle * $pi / 1800; map { # polar equation of a logarithmic spiral ($radius=exp($angle)); # the /9 is shorter than /10 :) and makes it a tighter spiral # $_ holds the offset within this map - which gives the spiral a width # (thinking about it i could have just added it to the radius) $radius = exp( ( $radians + $_ / 9 ) / 9 ) / 9; # this is the reiman projection (project from a plane through a sphere # to its north pole - mark where it meets the sphere) # also the conversion to cartesian coords $x = ( 1 / ( $radius + 1 / $radius ) ) * cos $radians; $y = ( 1 / ( $radius + 1 / $radius ) ) * sin $radians; # this sets the pixel in the image vec( $image, # and this works out the offset for the correct byte to set # (offset=$x+$width(140) *$y) int( # this is the new $x - using an isometric conversion: # ($x'= $x+$y - rotate through 45 degrees) 70 * ( 1 + $x + $y ) + # this is new $y - ($y'=$z+($y-$x)/2 (squish it) 140 * ( 10 + int( 15 + 80 * # the height at which the projection meets the sphere ($z) $radius**2 / ( 1 + $radius**2 ) + 40 * ( $y - $x ) ) ) ), 8 ) # and this changes the colour based on the angle of our rotation = ( $pi / 2 + $radians ) % ( 2 * $pi ) > $pi ? 2 : 1 # /map to give width } 0 .. 15 } # print the image print f $image

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: obfuscated [id://555043]
Approved by wazoox
Front-paged by grinder
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2024-04-19 20:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found