[Contents]

output::asciiArt -- A domain for 2D ascii art graphics

Introduction

This domain allows for creating 2D ascii art graphics, which can be displayed by the text pretty-printer of MuPAD.

Details

Creating Elements


output::asciiArt(list)

Parameters

list- A list of strings.

Details

Method fromArray: boxed cell graphic from 2D array

Method width: width of a graphic

Method height: height of a graphic

Method alignment: vertical alignment

Method setAlignment: sets the vertical alignment

Method flipx: horizontal flip

Method flipy: vertical flip

Example 1

We demonstrate some basic usage of this domain. Here is a little graphic:
>> a := output::asciiArt([" \\_/ ", "| _ |", "|o o|", "//|\\\\", " ___"])
     
                                    ___
                                   //|\\
                                   |o o|
                                   | _ |
                                    \_/
        
The output is not yet quite perfect, but such a graphic can be included in a complex formula:
>> (2*a + 1)/(x + a^2)
     
                                   ___
                                  //|\\
                                2 |o o| + 1
                                  | _ |
                                   \_/
                                -----------
                                      ___ 2
                                     //|\\
                                 x + |o o|
                                     | _ |
                                      \_/
        
We fetch some information on this graphic. This is its size:
>> [a::dom::height(a), a::dom::width(a)]
     
                                  [5, 5]
        
Here are some of its characters:
>> a[1, 1], a[3, 1], a[1, 3], a[2, 3]
     
                            " ", "_", "|", "o"
        
Fetching a character out of bounds raises an error.
>> a[6, 6]
     
      Error: Out of range [output::asciiArt::_index]
        

The graphic can more or less be fliped around:

>> a::dom::flipx(a)
     
                                    ___
                                   \\|//
                                   |o o|
                                   | _ |
                                    /_\
        

>> a::dom::flipy(a)
     
                                    \_/
                                   | _ |
                                   |o o|
                                   //|\\
                                    ___
        

>> a::dom::transpose(a)
     
                                    /_\
                                   | _ |
                                   |o o|
                                   \\|//
                                    ___
        

It is time to do some drawing now:

>> a[2, 3] := "v":
   a
     
                                    ___
                                   //|\\
                                   |v o|
                                   | _ |
                                    \_/
        
>> a[3, 5] := a[4, 6] := "/":
   a[4, 7] := "ooo": a[5, 8] := a[5, 6] := "o":
   a;
     
                                      o
                                     ooo
                                     /o
                                   _/_
                                  //|\\
                                  |v o|
                                  | _ |
                                   \_/
        

All of this does not look very serious, does it? Well, do not be misleaded. This hack is very hand for quick and simple display of combinatorial structures. And as usual with combinatorics, fun and seriousness are never very far away.

>> combinat::dyckWords::printPretty([1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0])
     
                                         /\
                            /\          /  \/\
                           /  \/\/\  /\/      \
                          /        \/          \
        
>> combinat::binaryTrees(([1, [1,[1], [1]], [1, [],[1]]]));
     
                                     o
                                   /  \
                                  / \  \
        
>> combinat::partitions::printPretty([5, 3, 1])
     
                           +---+
                           |   |
                           +---+---+---+
                           |   |   |   |
                           +---+---+---+---+---+
                           |   |   |   |   |   |
                           +---+---+---+---+---+
        
>> combinat::tableaux::printPretty([[3], [1, 2, 4]])
     
                               +---+
                               | 3 |
                               +---+---+---+
                               | 1 | 2 | 4 |
                               +---+---+---+
        

Example 2

The constructor output::asciiArt::fromArray is handy to create graphics with boxed cells. Here is how to draw a ribbon:

>> output::asciiArt::fromArray(
       array(1..6, 1..6,
             (3, 1) = 1, (3, 2) = 3, (3, 3) = 5,
                                     (2, 3) = 4, (2, 4) = 6,
                                                 (1, 4) = 2))
     
                             +---+---+---+
                             | 1 | 3 | 5 |
                             +---+---+---+---+
                                     | 4 | 6 |
                                     +---+---+
                                         | 2 |
                                         +---+
        

Changes

[Contents]


MuPAD Combinat, an open source algebraic combinatorics package