This post originated from an RSS feed registered with Ruby Buzz
by Christian Neukirchen.
Original Post: Making of: The XMasHack 2005
Feed Title: chris blogs: Ruby stuff
Feed URL: http://chneukirchen.org/blog/category/ruby.atom
Feed Description: a weblog by christian neukirchen - Ruby stuff
Maybe you already saw my yearly christmas greeting on ruby-talk:172428
(last year’s to be found here),
but today I’d like to explain how I did it. If you didn’t run it yet,
do that now and be amazed. ;-)
First of all, I needed to implement the actual logic. I’d only like
to outline it here and leave the rest for the reader. You may want to
read the complete, unobfusciated
source.
The real snowfall happens in snowdrop!, where a random vector of
snow heights gets increased by one in a way the difference to the
neighbour elements is never greater than one. This vector then gets
rendered in to_s onto a marshalled array with the greeting message
by differentiating the vector and thereby figuring out which chars to
use. Above the skyline snow randomly gets painted.
All this happens until all the vector’s elements are filled up. The
logic is not very difficult but I tried quite a few ways to make it
work best. I’d like to thank Frixon on #ruby-de for the inspiration;
he had to write the mountain algorithm in Ada (I didn’t look at the
code, only at the output).
Of course, that was the easy part. ;-) Now, the thing had to be
styled. Since this years hack was a lot bigger than last years (2221
byte), I couldn’t simply reuse last years fir
tree. I first tried to add some
thicker border to it, but then I thought it would be boring if I
used the same image twice.
So I took the PostScript star of
first advent, gimped it a bit (solid fill, rescaling to an appropriate
size and ratio since terminal fonts aren’t 1:1), then saved it into a
portable grey map and solarized it into ASCII chars using a
self-written script. The rest of the
image (border and snow) was made manually using Emacs’ picture-mode.
The final ASCII image, consisting of * and and some custom text
was then filled with code, using a similar
script like last year.
It was some hours of work, some hours of fun and I hope you enjoyed it!