Thank you to anyone who has already donated - your generous donations helped make three months of treatment possible.

My brother Nate continues to fight stage IV Hodgkin's lymphoma. He's just 31, with a wife and baby girl. They have no active income (since he's been unable to return to work), no insurance, and cannot afford the treatment he needs. Nate and his family need your help. Please consider a donation, every dollar helps. Thanks.


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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#! /usr/bin/perl

# Copyright (C) 2009 Xyne
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.


use strict;
use warnings;

use Image::Magick;

my $OPTIONS = {
  # the output file (file extension determines type))
  '--file'    => 'img.png',
  
  # background color (grid)
  '--bg'      => '#050505',
  
  # image to overlay
  '--image'   => undef,
  
  # palette for tiles (imagemagick colors)
  '--palette' => '#0f0f0f #101010 #121212 #0c0c0c #111111',
  
  # how to overlay image (0:normally, 1+2:blocky)
  '--blocky'  => 0,
  
  # size of final image
  '--size'    => undef,
  
  # size of tiles
  '--tile'    => 7,
  
  # gravity of overlaid image (imagemagick parameter)
  '--gravity' => 'Center'
};

my $option;
foreach my $arg (@ARGV)
{
  if (substr($arg,0,1) eq '-')
  {
    $option = $arg;
  }
  elsif (defined($option))
  {
    $OPTIONS->{$option} = $arg;
  }
}


my $width;
my $height;
if (defined($OPTIONS->{'--size'}) and $OPTIONS->{'--size'} =~ m/^(\d+)x(\d+)$/)
{
  $width = $1;
  $height = $2;
}
else
{
  print "error: no size given\nusage: \"--size <width>x<height>\"\n";
  exit 1;
}
my @palette = split(/\s+/,$OPTIONS->{'--palette'});
my $file = $OPTIONS->{'--file'};
my $bg = $OPTIONS->{'--bg'};

my $image = Image::Magick->new();
$image->Set(size=>"${width}x${height}");
$image->ReadImage('xc:none');

my $img = $OPTIONS->{'--image'};
my $logo = Image::Magick->new();
if (defined($img))
{
  $logo->Set(background=>'none');
  $logo->ReadImage($img);
}

my $gravity = $OPTIONS->{'--gravity'};
$image->Composite(image=>$logo,gravity=>$gravity) if $OPTIONS->{'--blocky'} > 0 and defined($img);
my $f = $OPTIONS->{'--tile'};
my $n = scalar(@palette);
my $prog = 0;
my $total = int($width*$height/($f**2));
my $cols = `tput cols` - 2;
system('tput civis');

for (my $i=0;$i<$width/$f;$i++)
{
  for (my $j=0;$j<$height/$f;$j++)
  {
    my ($x1,$y1) = ($i*$f,$j*$f);
    my ($x2,$y2) = ($x1+$f-2,$y1+$f-2);
    
    my $r = int(rand($n));
    my $color = $palette[$r];
    
    if ($OPTIONS->{'--blocky'} > 0 and defined($img))
    {
      my ($red,$green,$blue,$alpha) = (0,0,0,0);
      for (my $k=$x1;$k<=$x2;$k++)
      {
        for (my $l=$y1;$l<=$y2;$l++)
        {
          my ($r,$g,$b,$a) = $image->GetPixel(y=>$l,x=>$k,channel=>'All');
          $red += $r;
          $green += $g;
          $blue += $b;
          $alpha += $a;
        }
      
      }
      if ($alpha/(($f-1)**2) < 0.5)
      {
        my $d = ($f-1)**2;
        $d -= $alpha if $OPTIONS->{'--blocky'} > 1;
        $color = sprintf("rgba(%d,%d,%d,1)",int(0xFF*$red/$d),int(0xFF*$green/$d),int(0xFF*$blue/$d));
      }
    }
    my ($m,$n) = ($x2+1,$y2+1);
    $image->Draw(fill=>$bg, primitive=>'rectangle', points=>"$x2,$y1 $m,$n");
    $image->Draw(fill=>$bg, primitive=>'rectangle', points=>"$x1,$y2 $m,$n");
    $image->Draw(fill=>$color, primitive=>'rectangle', points=>"$x1,$y1 $x2,$y2");
    
    $|++;
    $prog++;
    my $disp = int($prog*$cols/$total);
    $disp = $cols if $disp>$cols;
    print "\r[".('=' x $disp).(' ' x ($cols-$disp)).']';
  }
}
system('tput cnorm');

$image->Composite(image=>$logo,gravity=>$gravity) if $OPTIONS->{'--blocky'} < 1 and defined($img);
$image->Write(filename=>$file);
print "\nsaved image as $file\n";