Tuesday, November 13, 2012

Just in Time for the End of the World: a Mayan Calendar Generation Program

OK, just kidding...my wife and I don't really believe that the world
is coming to an end at the end of the current Mayan Great Cycle.
And to demonstrate our optimism that we'll still be here after
December 21st of this year, we are finally releasing the first
version of our Mayan calendar generation program (written in
Clojure, of course).  Version 1.0.0 is available on GitHub at
https://github.com/hickst/mayancal.

The Mayancal program generates a PDF file containing an illustrated
Mayan calendar for the specified year (the default is 2012...just in
case). The earliest year available is 1900, but this should allow
most users to generate a calendar for their birth year.

The Maya developed a sophisticated calendar based on the
intersection of various cycles, especially the 260 day Tzolkin
(ritual calendar) and the 365 day Haab (a rough solar calendar). The
Tzolkin named each day; like our days of the week. There were 20 day
names, each represented by a unique symbol. The days were also
numbered from 1 to 13 (Trecena cycle). Since there were 20 day
names, after the count of thirteen was reached the next day was
numbered 1 again. Since 13 and 20 have no common divisors, this
system uniquely represents all 260 (13*20) days of the sacred year
with a unique number and day-name combination.

The Haab was a rough solar year of 365 days. The Haab year contained
named months called Uinals. These were 18 regular months of 20 days
each and one special five-day month called Uayeb. Days of the Haab
months were numbered 0 to 19. Each day had a number and day name
from the 260-day Tzolkin as well as a number for each day of the
Haab month (Veintena cycle). Using the intersections of these
cycles, each day can be identified by a four-tuple:
[Tzolkin number, Tzolkin day, Haab number, Haab month].

Using Clojure's infinite lazy sequences these interacting cycles can
easily be generated and combined together with an infinite Gregorian
date sequence (see the mcal.clj file in the source code). To
simplify the program, all sequences are synchronized to start at the
Gregorian date of 1/1/1900. Any given point is then found by
dropping the appropriate number of elements from the heads of the
synchronized sequences.

Some miscellaneous notes: Because of the many great public domain
images and icons used to illustrate the calendar, the output PDF
file tends to be rather large so you probably don't want to email
calendars to all your relatives for Christmas. Also, we've tried
viewing the calendar in Preview 5.5.3, Adobe Reader 10.0.1, Skim
1.3.22, and GoodReader for iPad 3.18.6 and we've seen a few
differences between these viewers. Only Adobe and GoodReader, for
example, were able to follow the embedded links and GoodReader had
trouble displaying the links on the last page.

As I said, this is version 1, so if you encounter any issues please
let us know. We hope that this toy provides you with some fun and
diversion from the more serious, real-world uses of Clojure.