-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathcolour
executable file
·84 lines (73 loc) · 1.56 KB
/
colour
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env perl
use Data::Dumper;
use FindBin;
use lib "$FindBin::Bin/lib";
use Geo::Coordinates::OSGB qw(ll_to_grid grid_to_ll);
use Minecraft;
use Elevation;
use Minecraft::Projection;
use Minecraft::MapTiles;
use Getopt::Long;
BEGIN { do "$FindBin::Bin/config/colours"; }
use strict;
use warnings;
my $point;
my $ll;
my $help;
if( !GetOptions (
"point=s" => \$point,
"ll" => \$ll,
"help" => \$help,
)) {
print STDERR ("Error in command line arguments\n");
help();
exit( 1 );
}
if( $help )
{
help();
exit( 0 );
}
sub help
{
print "$0 [--ll] --point <x>,<y>\n";
}
if( !defined $point )
{
die "Please define a point";
}
my( $x,$y ) = split( ",", $point );
my( $lat,$long );
if( $ll )
{
($lat,$long)=( $x,$y);
}
else
{
($lat,$long) = Elevation::en_to_ll( $x,$y);
}
if( !-d "$FindBin::Bin/var" ) { mkdir( "$FindBin::Bin/var" ); }
if( !-d "$FindBin::Bin/var/tiles" ) { mkdir( "$FindBin::Bin/var/tiles" ); }
my $tiles = new Minecraft::MapTiles(
zoom=>19,
spread=>3,
width=>256,
height=>256,
dir=>"$FindBin::Bin/var/tiles",
url=>"http://b.tile.openstreetmap.org/",
default_block=>1,
);
my @colours = $tiles->spread_colours( $lat,$long );
my $scores = {};
foreach my $col ( @colours )
{
$scores->{$col}++;
}
print " COUNT | COLOUR | BLOCK\n";
print "---------+-------------+--------\n";
foreach my $col ( sort { $scores->{$a}<=>$scores->{$b} } keys %$scores )
{
my $block = $Minecraft::Config::COLOURS->{$col};
print sprintf( "%8d | %11s | %s\n", $scores->{$col}, $col, defined $block?$block:"???" );
}
exit 0;