I wanted to see what an edge walker looked like in the "strings/regex" domain...

#!/usr/bin/perl # http://perlmonks.org/?node_id=1204060 use strict; use warnings; my @points = points(); my ($minx, $miny, $maxx, $maxy) = ( $points[0][0], $points[0][1], $points[0][0], $points[0][1]); for (@points) { my ($x, $y) = @$_; $minx > $x and $minx = $x; $miny > $y and $miny = $y; $maxx < $x and $maxx = $x; $maxy < $y and $maxy = $y; } my $height = $maxy - $miny + 3; # some useful stuff my $width = $maxx - $minx + 3; my $gw = $width + 1; # grid width (distance to down one row) my $gwm3 = $gw - 3; my @letters = ('A' .. 'Z', 'a' .. 'z'); # label points by letter seque +nce my @steps = (1, $gw+1, $gw, $gw-1, -1, -$gw-1, -$gw, -$gw+1); # by dir +ection my $grid = ( ' ' x $width . "\n" ) x $height; my @answerpoints; # coordinates around edge for (@points) # put points on grid (multiline string :) { my ($x, $y) = @$_; substr $grid, (($y - $miny + 1)) * $gw + ($x - $minx + 1), 1, '#'; } my $direction = 0; # start facing east (increases clockwise) my $start = my $at = $grid =~ /(?<= )#/ ? $-[0] : die "empty"; # at to +pleft do # clockwise walk around edge { push @answerpoints, [ $at % $gw - 1 + $minx, int $at / $gw - 1 + $mi +ny ]; pos($grid) = $at - $gw - 1; # northwest corner neighbor $grid =~ /\G(.)(.)(.).{$gwm3}(.).(.).{$gwm3}(.)(.)(.)/s; # all neigh +bors ("$1$2$3$5$8$7$6$4" x 2) =~ /^.{$direction} *(#)/ and # rotate & sca +n $at += $steps[ $direction = ( $-[1] - 3 ) % 8 ]; # step in new dir +ection } until( $at == $start ); my $i = 0; for (@answerpoints) # add letters for display if wanted { my ($x, $y) = @$_; pos($grid) = $x - $minx + 1 + ($y - $miny + 1) * $gw; $grid =~ s/\G#/$letters[$i++ % @letters]/; # label point if not } print $grid; #use Data::Dump 'pp'; pp \@answerpoints; # the real answer :) sub points { [527,83],[527,84],[526,84],[525,84],[524,84],[523,84],[522,84], ... some points deleted to shorten listing ... [534,113],[533,113],[532,113],[531,113],[530,113], }

Outputs:

A MNOPQRSB KL#######C J########D I########E k H##########FG O j#l G#############HIJKLMNP i#m F#####################Q h#no E#####################R g##pq D#####################S f###rs C#####################T e#####tuvw B#####################U d#########xyzA######################V c###################################W baZ#################################X Y################################Y X################################Z W################################a V###############################b U###############################c T###############################d S##############################e R##############################f Q##############################g P############################h ONMLK#######################i JIHGFED################j CBAz############k yxwvut######l s####m rqpon

Sure saves a lot of that ugly subscripting :)

UPDATE: New and Improved!! Now with Tk!! see Re^2: Polygon Creation -- Request for Algorithm Suggestions


In reply to Re: Polygon Creation -- Request for Algorithm Suggestions by tybalt89
in thread Polygon Creation -- Request for Algorithm Suggestions by golux

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.