(archive 'newLISPer)

December 12, 2009

Seasonal greetings

Filed under: newLISP — newlisper @ 09:17

Not functional in the archive version.


Seasonal greetings from Unbalanced Parentheses Headquarters!

(for (i 0 255)
(push (list (rand 250) (rand 250) (rand 250) (max 0.3 (random 0 1))) colour-map -1))

(define (greet text x y)
(local (colour) (set ‘colour (colour-map (rand 100)))
(write-buffer page (string (format {a_context.fillStyle = ‘rgba(%d, %d, %d, %f)’; } colour) “\n”
(format {a_context.font = ‘%dpx sans-serif’; } (max 10 (rand 24))) “\n”
(format {a_context.fillText (‘%s’, %d, %d); } text x y) “\n” ))))

(set ‘page {})

(define (make-canvas nm width height)
(write-buffer page
(format (string (char 60) {canvas id=”%s” width=”%d” height=”%d”} (char 62) (char 60) {/canvas} (char 62)) nm width height)))

(seed (date-value))

(set ‘width 800 ‘height 1200)

(make-canvas “a” width height)

(write-buffer page
(char 60)
{script type=”text/javascript” language=”javascript” charset=”utf-8″}
(char 62)
{var a_canvas = document.getElementById(“a”); } “\n”
{var a_context = a_canvas.getContext(“2d”); } “\n”
{a_context.font = “bold 12px sans-serif”; } “\n”
“\n” ))

(dotimes (i 200)
(greet (amb “Hyvää joulua ja onnellista uutta vuotta”
“Joyeux Noël et bonne année”
“Fröhliche Weihnachten und ein gutes neues Jahr”
“Nollick Ghennal as Blein Vie Noa”
“Buon Natale e felice anno nuovo”
“Veselé vánoce a šťastný nový rok”
“God jol og godt nyttår”
“Linksmų Kalėdų ir laimingų Naujųjų Metų”
“Crăciun fericit şi un An Nou Fericit”
“Natale hilare et annum faustum”
“Merry Christmas”
“Zorionak eta urte berri on”
“Gleðileg jól og farsælt nýtt ár”
“(println {Happy newLISPing})”
“Seasons Greetings”
“शुभ क्रिसमस”
“Καλά Χριστούγεννα!”
“Bonan Kristnaskon kaj feliĉan novan jaron”
“Prettige kerstdagen en een Gelukkig Nieuwjaar!”
“Sretna Nova godina!”
“Rõõmsaid Jõule ja Head Uut Aastat”
“Nollaig chridheil agus bliadhna mhath ùr”
“Nadolig llawen a blwyddyn newydd dda”
“Priecīgus Ziemassvētkus un laimīgu Jauno gadu”
“Веселого Різдва і з Новим Роком”
“С наступающим Новым Годом”)
(rand (- width 100)) (rand (+ height 200))))
(write-buffer page (string (char 60) {/script} (char 62)))

This post uses the HTML 5 Canvas, and should work properly on recent standards-compliant browsers such as Safari, Firefox, and Google Chrome. The Opera browser can’t handle this, which surprised me. As for Internet Explorer … I suspect you won’t see anything. Also, even if the canvas works well, there’s still the problem of all those Unicode fonts. We haven’t completely left behind the early days of the web, when every other page had a “Best viewed in browser X” banner.

The image is generated afresh each time you load the page, so the colours and positions of the various greetings are different each time. This is because the image is generated by embedded newLISP code in the HTML database which is evaluated only at browse time. The only tricky part of the operation is to make sure the code survives being translated by Markdown into HTML, then being uploaded via xmlrpc to be stored in the newLISP database ready for being processed by Dragonfly.

If you want a challenge, see how many different languages you can identify (without cheating)!


Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: