AsciiArtGenerator is a utility class that converts text strings into large ASCII art characters.
It provides a simple interface for generating stylized text that can be used in console output,
logging, and user interfaces to enhance visual presentation.
Features
Text to ASCII Art - Converts strings to large ASCII art characters
Custom Character Support - Add custom character mappings
Built-in Character Set - Supports letters, numbers, and common symbols
Uppercase Conversion - Automatically converts input to uppercase
Memory Efficient - Optimized for embedded systems
Thread Safe - Safe for use in multi-threaded environments
classAsciiArtGenerator{public:// Constructor and destructorAsciiArtGenerator()noexcept;~AsciiArtGenerator()noexcept=default;// Core ASCII art generationstd::stringGenerate(conststd::string&input)constnoexcept;// Custom character managementvoidAddCustomCharacter(charcharacter,conststd::vector<std::string>&art_lines)noexcept;voidRemoveCustomCharacter(charcharacter)noexcept;voidClearCustomCharacters()noexcept;// Character support validationboolIsCharacterSupported(charcharacter)constnoexcept;std::stringGetSupportedCharacters()constnoexcept;private:std::map<char,std::vector<std::string>>custom_characters*;std::vector<std::string>GetCharacterArt(charcharacter)constnoexcept;};```bash## Built-in Character Set
The`AsciiArtGenerator`includesacomprehensivesetofASCIIartcharacters:-**Letters**:A-Z(uppercaseonly)-**Numbers**:0-9-**Symbols**:!@#$%^&*()[]{}|\/;:'" < > ` ~- **Punctuation**: . , ? - * = +Each character is represented as a 6-line ASCII art pattern with consistent width and height.## Usage Examples### Basic ASCII Art Generation```cpp#include "utils/AsciiArtGenerator.h"// Create generator instanceAsciiArtGenerator generator;// Generate ASCII art for textstd::string hello_art = generator.Generate("HELLO");printf("%s\n", hello_art.c_str());// Generate ASCII art for numbersstd::string number_art = generator.Generate("123");printf("%s\n", number_art.c_str());// Generate ASCII art for mixed contentstd::string mixed_art = generator.Generate("ESP32-C6");printf("%s\n", mixed_art.c_str());
AsciiArtGeneratorgenerator;// Add custom characterstd::vector<std::string>custom_char={" *** "," / \\ ","| |","| |"," \\***/ "," "};generator.AddCustomCharacter('@',custom_char);// Generate text with custom characterstd::stringcustom_art=generator.Generate("TEST@");printf("%s\n",custom_art.c_str());// Remove custom charactergenerator.RemoveCustomCharacter('@');// Clear all custom charactersgenerator.ClearCustomCharacters();
Character Support Validation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
AsciiArtGeneratorgenerator;// Check if character is supportedif(generator.IsCharacterSupported('A')){printf("Character 'A' is supported\n");}if(generator.IsCharacterSupported('โฌ')){printf("Character 'โฌ' is supported\n");}else{printf("Character 'โฌ' is not supported\n");}// Get list of supported charactersstd::stringsupported=generator.GetSupportedCharacters();printf("Supported characters: %s\n",supported.c_str());
Integration with Logging
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include"utils/AsciiArtGenerator.h"
#include"mcu/esp32/EspLogger.h"// Create generator and loggerAsciiArtGeneratorgenerator;EspLoggerlogger(config);logger.EnsureInitialized();// Generate ASCII art bannerstd::stringbanner=generator.Generate("SYSTEM STARTUP");logger.Log(hf_log_level_t::LOG_INFO,"APP","ASCII Art Banner:\n%s",banner.c_str());// Generate test resultsstd::stringresult=generator.Generate("SUCCESS");logger.Log(hf_log_level_t::LOG_INFO,"TEST","Test Result:\n%s",result.c_str());
Memory Usage: ~2KB for built-in character set + custom characters
Execution Time: <1ms per character generation
Thread Safety: Fully thread-safe
Flash Usage: ~2KB for all built-in patterns
Character Height: 6 lines per character
Character Width: Variable (typically 6-8 characters wide)
Customization
The AsciiArtGenerator can be extended with custom characters by adding them at runtime:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
AsciiArtGeneratorgenerator;// Add custom character with 6-line ASCII artstd::vector<std::string>custom_char={" *** ",// Line 1" / \\ ",// Line 2"| |",// Line 3"| |",// Line 4" \\***/ ",// Line 5" "// Line 6};generator.AddCustomCharacter('@',custom_char);// Now '@' can be used in text generationstd::stringemail_art=generator.Generate("TEST@EXAMPLE");printf("%s\n",email_art.c_str());
Custom Character Requirements
Height: Must be exactly 6 lines
Width: Should be consistent (typically 6-8 characters)
Format: Each line should be a string with consistent padding
Characters: Use standard ASCII characters for best compatibility