(I). I got a software which contains a command "rectangle(x1,x2,y1,y2)", it can generate a rectangle with bottom-left corner coordinate(x1,y1) and upper-right corner coordinate(x2,y2) on x-y plane
(II). I wanna use this software to create all alphanumeric in x-y plane with stack up rectangles, basically I wanna print out those commands by perl
(III). My idea is to create a 5x7 table by filling this table with rectangles then put it to the coordinate I want as following:
#!/usr/bin/perl
use strict;
use warnings;
###=================================================================================###
###=================================================================================###
###========= This script will generate alphanumeric by filling polygon in =========###
###==================== the specific position of a 5 x 7 table =====================###
###================= following case represents the alphanumeric:"1"================###
###=================================================================================###
###=== --------------------- ===###
###=== | | | O | | | 6 ===###
###=== --------------------- ===###
###=== | | O | O | | | 5 ===###
###=== --------------------- ===###
###=== | | | O | | | 4 ===###
###=== --------------------- ===###
###=== | | | O | | | 3 row number ===###
###=== --------------------- ===###
###=== | | | O | | | 2 ===###
###=== --------------------- ===###
###=== | | | O | | | 1 ===###
###=== --------------------- ===###
###=== | | O | O | O | | 0 ===###
###=== ----------*---------- "*" stand for (coor_x, coor_y) ===###
###=== -2 -1 0 1 2 --> column number ===###
my grid_x = 1; # the size of a grid along x-direction
my grid_y = 1; # the size of a grid along y-direction
sub alphanum_1 {
my $coor_x = shift; # the x coordinate that I wanna put this "polygon 1"
my $coor_y = shift; # the y coordinate that I wanna put this "polygon 1"
my ($i,$j,$mkrstring);
my @col_neg2 = (""); # the positions which needs to be filled in col -2
my @col_neg1 = (0,5); # the positions which needs to be filled in col -1
my @col_zero = (0,1,2,3,4,5,6); # the positions which needs to be filled in col 0
my @col_pos1 = (0); # the positions which needs to be filled in col +1
my @col_pos2 = (""); # the positions which needs to be filled in col +2
my (@marker,@anchor);
for ($i=0; $i<=$#col_zero-1; $i++) {
$marker[$i] = ($col_zero[$i+1] - $col_zero[$i] == 1)? "m" : "0";
$mkrstring = $mkrstring.$marker[$i];
}
}
&alphanum_1;
Here comes the problem, as you can see the column 0 needs to be filled by all 7 rows, if I only want to use the "rectangle" command once instead of 7 times :
assume that coor_x=0, coor_y=0
method 1:
rectangle(-0.5,0.5,0,7)
method 2:
rectangle(-0.5,0.5,0,1)
rectangle(-0.5,0.5,1,2)
rectangle(-0.5,0.5,2,3)
rectangle(-0.5,0.5,3,4)
rectangle(-0.5,0.5,4,5)
rectangle(-0.5,0.5,5,6)
rectangle(-0.5,0.5,6,7)
method 1 and 2 will achieve the same result, but I prefer to use method 1 which means I need to check the "neighborhood relationship" in the same column, but I got stuck in this part, basically, I wanna stick the rectangles as long as they can be stuck together in the same column.
I'm a newbie in perl, is there any hint? I need your help!