# Using Text on the LED Matrix

Using text on the LED Matrix is very similar to using Sprites. In fact, text is just a Sprite made up of strings of text. Anything you can do with a Sprite, you can also do with Text — it can be rotated, cropped, flipped and drawn on the Framebuffer.

To create Text, you can use the the `Text()` function:

    Text(text)

where `text` is a string you want displayed. Text also has some optional parameters — for example, you can call `Text()` with:

    Text(text, char_spacing=1, font_name='5x7')

Both optional parameters have the defaults as shown — but you can change them. The char_spacing is the number of blank points between characters in the text — the higher the number, the further apart the text is spaced. The font_name is the font that is used for the text. There are two choices for font: '5x7' and '3x5', and they are named according to the max width and height of the characters they use.

For example, the letter 'A' could be created and displayed with the `draw()` function, as follows:

from rstem.led_matrix import Text from rstem.led_matrix import FrameBuffer fb = FrameBuffer() my_text = Text('A') fb.erase() fb.draw(my_text) fb.show()

# Examples

Here's a set of examples of things we can do with Text on the LED Matrix. All the examples use the letter 'P', but, of course, you could use any text you'd like:

from rstem.led_matrix import Text from rstem.led_matrix import FrameBuffer fb = FrameBuffer() my_text = Text('P') fb.erase() fb.draw(my_text) fb.show()

Here are some of the things we could do to the Text by modifying the `fb.draw()` function above (and potentially adding lines before it). Along with each example is a demonstration of what the text would look like for each operation:

Functions | LED Matrix
--- | ---
`fb.draw(my_text)` |
    00000000
    FFFF0000
    F000F000
    F000F000
    FFFF0000
    F0000000
    F0000000
    F0000000
`# Shift right and up` `fb.draw(my_text, (2,3))` |
    00F000F0
    00FFFF00
    00F00000
    00F00000
    00F00000
    00000000
    00000000
    00000000
`# Crop the top of the P` `my_text.crop((0,3), (8,8))` `fb.draw(my_text)` |
    00000000
    00000000
    00000000
    00000000
    FFFF0000
    F000F000
    F000F000
    FFFF0000
`# Draw cropped top shifted right and up` `my_text.crop((0,3), (8,8))` `fb.draw(my_text, (3,4))` |
    000FFFF0
    000F000F
    000F000F
    000FFFF0
    00000000
    00000000
    00000000
    00000000
`# Rotate 90 degrees` `my_text.rotate(90)` `fb.draw(my_text)` |
    00000000
    00000000
    00000000
    0FF00000
    F00F0000
    F00F0000
    F00F0000
    FFFFFFF0
`# Rotate 180 degrees` `my_text.rotate(180)` `fb.draw(my_text)` |
    00000000
    0000F000
    0000F000
    0000F000
    0FFFF000
    F000F000
    F000F000
    0FFFF000
`# Rotate 270 degrees` `my_text.rotate(270)` `fb.draw(my_text)` |
    00000000
    00000000
    00000000
    FFFFFFF0
    000F00F0
    000F00F0
    000F00F0
    0000FF00
`# Flip horizontally` `my_text.flip(vertical=False)` `fb.draw(my_text)` |
    00000000
    0FFFF000
    F000F000
    F000F000
    0FFFF000
    0000F000
    0000F000
    0000F000
`# Flip veritcally` `my_text.flip(vertical=True)` `fb.draw(my_text)` |
    00000000
    F0000000
    F0000000
    F0000000
    FFFF0000
    F000F000
    F000F000
    FFFF0000
`# Crop eyes and mouth, then rotate` `my_text.crop((0,3), (8,8)).rotate(90)` `fb.draw(my_text)` |
    00000000
    00000000
    00000000
    0FF00000
    F00F0000
    F00F0000
    F00F0000
    FFFF0000
`# Crop, rotate, then reset` `# Original image will be restored!` `my_text.crop((0,3), (8,8)).rotate(90).reset()` `fb.draw(my_text)` |
    00000000
    FFFF0000
    F000F000
    F000F000
    FFFF0000
    F0000000
    F0000000
    F0000000