Need help making a "Perl" program work for my mac.
Posted: 2010-11-14 03:26pm
For those following my Dwarf Fortress game, recently I started deisgning a very elaborate city that is taking forever to do. looking at the Bay12 DF forums, apprently someone wrote a program that can automaticlly designate, not just circles, but "domes" as well.
There was even a bit about how to load it, but I want to make sure I am doing this rigth before messing around in my system:I wrote a quick Perl program to designate my spherical dome correctly. It has radius 20, for a different radius change $r. Non-integer values of $r may look better for circles, but I use whole numbers for spheres.
Code: Select all
#!/usr/bin/perl use Tk; $Z = 0; ################### EDIT RADIUS HERE ########################## $r = 20; ############################################################### $R = int(2*$r) - int(int(2*$r)-$r); $mw = tkinit(); $cv = $mw->Canvas(-width => (2*$R+1)*16, -height => (2*$R+1)*16)->pack(); for my $y (0..2*$R) { for my $x (0..2*$R) { $cv->create("rectangle", $x*16, $y*16, ($x+1)*16, ($y+1)*16, -fill => "white", -tags => ["t $y $x"]); } } $cv->create("text", 0, 0, -anchor => "nw", -text => "Level 0", -font => "Helvetica 24", -fill => "yellow", -tags => ["text"]); $mw->bind("<less>", sub {$Z++; upd()}); $mw->bind("<greater>", sub {$Z--; upd()}); $mw->bind("<space>", \&upd); $mw->bind("<Escape>", sub {exit}); upd(); MainLoop; sub upd { $cv->itemconfigure("text", -text => "Level $Z"); for my $y (0..2*$R) { for my $x (0..2*$R) { $col = (($x-$R)**2 + ($y-$R)**2 + $Z*$Z < $r*$r) ? "white" : (($x-$R)**2 + ($y-$R)**2 + ($Z-1)*($Z-1) < $r*$r) ? "#5f5f5f" : "black"; $cv->itemconfigure("t $y $x", -fill => $col); } } }
I am preparing to do an attempt tonight on my iMac and just want to know if there is anythign I should look out for before trying to run it.Save this thing as a plain-text .pl file with a no-format text file editor (TextEdit on Mac, disable RTF) and run it on a terminal (Applications -> Utilities):Perl should be installed by default on all systems other than Windows.Code: Select all
$ perl sphere.pl
BTW: The $ is the command prompt, don't type it.