Skip to content

Instantly share code, notes, and snippets.

@vaskozl
Created August 30, 2014 20:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vaskozl/24ae87908dfcac2ddcc7 to your computer and use it in GitHub Desktop.
Save vaskozl/24ae87908dfcac2ddcc7 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use strict;
use warnings;
use GD::Simple;
# create a new image (width, height)
my $width = 80;
my $height = 45;
my $img = GD::Simple->new($width, $height);
my $unused = $width;
my $range = 8;
my $minimum = 4;
while($unused>0){
my $roomlength = int(rand($range)) + $minimum;
my $roomwidth = int(rand($range)) + $minimum;
my $px = $width - $unused;
room($px,0,$roomwidth+$px,$roomlength,undef,'black');
$unused = $unused - $roomwidth;
print "starting at $px, ";
}
room(0,0,80,45,undef,'black');
sub room{
my ($tx,$ty,$bx,$by,$bg,$fg) = @_;
$img->bgcolor($bg);
$img->fgcolor($fg);
$img->rectangle($tx, $ty, $bx, $by); # (top_left_x, top_left_y, bottom_right_x, bottom_right_y)
# ($x1, $y1, $x2, $y2)
}
# convert into png data
open my $out, '>', 'img.png' or die;
binmode $out;
print $out $img->png;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment