Skip to content

Instantly share code, notes, and snippets.

@minikomi
Last active December 31, 2015 17:29
Show Gist options
  • Save minikomi/8020382 to your computer and use it in GitHub Desktop.
Save minikomi/8020382 to your computer and use it in GitHub Desktop.
merry xmas!
#! /usr/bin/env racket
#lang racket
(define (color-str n s)
(~a "\x1b[3" n "m" s "\x1b[0m"))
(define (tree n)
(append
(for/list ([r (range 1 (+ n 2) 2)])
(define not-space
(if (= 1 r)
'("*")
(for/list ([i (range r)])
(if (zero? (modulo (+ (* i 3) r) 7)) "o" "l"))))
(append (make-list (/ (- n r) 2) " ") not-space))
(list (append (make-list (/ (- n 3) 2) " ") (make-list 3 "b")))))
(define (animate-tree tree base leaf frame)
(display "\e[1;1H\e[2J")
(for ([row tree])
(for ([chr row])
(display
(case chr
[(" ") " "]
[("*") (if (even? frame)
(color-str 3 "*")
(color-str 3 "`"))]
[("o") (color-str (random 8) "o")]
[("l") (color-str 2 leaf)]
[("b") (color-str 3 base)])))
(newline))
(sleep 0.2)
(animate-tree tree base leaf (add1 frame)))
(define (go n-str base leaf)
(with-handlers
([exn:break? (lambda (e)
(display "\e[1;1H\e[2J")
(displayln "Merry Xmas!"))])
(animate-tree
(tree (string->number n-str)) base leaf 0)))
(apply go (vector->list (current-command-line-arguments)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment