Art Blocks

This section will go over the art macro and some video types.

dragon animation

Every part of the dragon is assigned its own variable, which are stitched together to form the final animation. Here's the source code of the dragon's head. You can click the above dragon to view the entire source file.

include video

define main of_type video as center_head

define center_head of_type video as loop art xii ix
   )  (     ...7..7.....    )  (    ....7..7....     )  (   .....7..7...
  ((__))    ..776677....   ((__))   ...776677...    ((__))  ....776677..
  /o..o\    ..636636....   /o..o\   ...636636...    /o..o\  ....636636..
 ( -vv- )   .6|6776|6...  ( -vv- )  ..6|6776|6..   ( -vv- ) ...6|6776|6.
  \ __. \   ..6|666|6...   ) __ (   ...6|66|6...   / .__ /  ...6|666|6..
   )     \  ...6|||||6..  /      \  ..6||||||6..  /     (   ..6|||||6...
  /       \ ..6|||||||6. /        \ .6||||||||6. /       \  .6|||||||6..
 '         ).6|||||||||6(          )6||||||||||6(         ` 6|||||||||6.
          ' ..||||||||6.            .||||||||||. `          .6||||||||..

This created the video with the art macro, made it loop nicely with the loop function, and assigned it to center_head. The include statement at the top included code for the video type and relevent functions.

The animation contains 3 frames and is 12x9 characters in size. The width and height come directly after the art keyword (using roman numerals). Every frame in the art macro is (2*width) by height in size, where the left half is the art and the right are the corresponding colors.

For the colors, 0..7 correspond to the ansi colors black, red, green, yellow, blue, magenta, cyan, and white. '|' marks a space character and '.' marks transparency.

The art macro isn't doing anything special. It expands into regular thorn code during the tokenization phase. This lets us do cool stuff like using single-letter local/global variables directly in the art macro.

Let's see what happens when we evaluate main.

~/code$ thorn
prepend frame empty_column cons_column horizontal empty_row cons_row 
empty_grid_cell cons_row empty_grid_cell cons_row full_grid_cell space 
cons_row full_grid_cell space cons_row full_grid_cell space cons_row 
full_grid_cell space cons_row ... and so on

When we enaluate main, we just get a value of type video, a tree of data constructors, a string of words when printed out. If you take this output and copy-paste it into main, It'll evaluate to the same thing.

To get an actual animation out of it, We must interprit it with an external program. thorn-to-sh and thorn-to-gif exist to do just that. They take thorn's output through stdin and generate the corresponding files. Here's how you would make and play a shell script animation.

~/code$ thorn | thorn-to-sh | sh
dragon animation

The video type is defined in video.th, colors in colors.th, characters in char.th, etc. You get the point. Just read the source code. A function's name and type should be enough to figure out what it does.

<< Types and Functions Lazy Evaluation >>