#!/usr/bin/ruby

#
## https://rosettacode.org/wiki/Munching_squares
#

require('GD');
 
var img = %O'GD::Image'.new(256, 256, 1);

var r = 0..255;

for y=r, x=r {
    var color = img.colorAllocate((255 - x - y).abs, (255-x)^y, x^(255-y));
    img.setPixel(x, y, color);
}
 
if (var fh = %f(xor.png).open('>:raw')) {
    fh << img.png;
}
