[英]How do you input an ASCII art image into the console in JS?
I'm trying to make this ASCII image shown in the console:我正在尝试在控制台中显示此 ASCII 图像:
_______
\ ___ `'. /| .--.
' |--.\ \ || |__|
| | \ ' || .--.
| | | ' || __ __ | |
| | | | _ _ ||/'__ '. .:--.'. | |
| | ' .'| ' / | |:/` '. '/ | \ || |
| |___.' /'.' | .' | || | |`" __ | || |
/_______.'/ / | / | ||\ / ' .'.''| ||__|
\_______|/ | `'. | |/\'..' / / / | |_
' .'| '/' `'-'` \ \._,\ '/
`-' `--' `--' `"
However, I'm getting multiple errors since I do not know how you would input this to make it show up in the console when I activate the code.但是,我遇到了多个错误,因为我不知道您将如何输入它以使其在激活代码时显示在控制台中。
Use a template literal to embed newlines in the string.使用模板文字在字符串中嵌入换行符。 You'll need to escape the backticks that are in the string.
您需要转义字符串中的反引号。
console.log(`_______ \\ ___ \\`'. /| .--. ' |--.\\ \\ || |__| | | \\ ' || .--. | | | ' || __ __ | | | | | | _ _ ||/'__ '. .:--.'. | | | | ' .'| ' / | |:\\` '. '/ | \\ || | | |___.' /'.' | .' | || | |\\`" __ | || | /_______.'/ / | / | ||\\ / ' .'.''| ||__| \\_______|/ | \\`'. | |/\\'..' / / / | |_ ' .'| '/' \\`'-'\\` \\ \\._,\\ '/ \\`-' \\`--' \\`--' \\`" `);
You could also just use figlet.你也可以只使用 figlet。 Make sure to install it first using npm i figlet
确保首先使用 npm i figlet 安装它
const figlet = require("figlet")
figlet.text("Text", function (err, data){
console.log(data)
})
The code above is a function to send text to the module "figlet" and get the text back as ascii art.上面的代码是一个将文本发送到模块“figlet”并将文本作为 ascii art 返回的函数。 Try changing the "text" to see your outcome.
尝试更改“文本”以查看结果。
You can use the template string literal: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals您可以使用模板字符串文字: https : //developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals
It can be done using the backtick charactere, example:可以使用反引号字符来完成,例如:
console.log(`%c _______ \\ ___ \\`'. /| .--. ' |--.\\ \\ || |__| | | \\ ' || .--. | | | ' || __ __ | | | | | | _ _ ||/'__ '. .:--.'. | | | | ' .'| ' / | |:/\\` '. '/ | \\ || | | |___.' /'.' | .' | || | |\\`" __ | || | /_______.'/ / | / | ||\\ / ' .'.''| ||__| \\_______|/ | \\`'. | |/\\'..' / / / | |_ ' .'| '/' \\`'-'\\` \\ \\._,\\ '/ \\`-' \\`--' \\`--' \\`" `, `font-family: monospace`);
You must arrange the ASCII:您必须安排 ASCII:
To view the font change, use the real console and not the one from StackOverflow
要查看字体更改,请使用真实控制台而不是 StackOverflow 中的控制台
You need to escape both the back tick characters and the back slash characters.您需要转义反引号字符和反斜杠字符。
const str = `_______ \\\\ ___ \\`'. /| .--. ' |--.\\\\ \\\\ || |__| | | \\\\ ' || .--. | | | ' || __ __ | | | | | | _ _ ||/'__ '. .:--.'. | | | | ' .'| ' / | |:/\\` '. '/ | \\\\ || | | |___.' /'.' | .' | || | |\\`" __ | || | /_______.'/ / | / | ||\\\\ / ' .'.''| ||__| \\\\_______|/ | \\`'. | |/\\\\'..' / / / | |_ ' .'| '/' \\`'-'\\` \\\\ \\\\._,\\\\ '/ \\`-' \\`--' \\`--' \\`" `; console.log(str);
Found this amazing online converter which can be used to escape JavaScript string发现了这个惊人的在线转换器,可以用来转义 JavaScript 字符串
Copy paste ASCII text to freeformatter, copy the escaped string to console.log("");复制粘贴ASCII文本到freeformatter,将转义的字符串复制到console.log("");
console.log("\r\n\u2591\u2588\u2588\u2588\u2588\u2588\u2557\u2591\u2591\u2588\u2588\u2588\u2588\u2588\u2557\u2591\u2588\u2588\u2588\u2557\u2591\u2591\u2588\u2588\u2557\u2591\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2591\u2588\u2588\u2588\u2588\u2588\u2557\u2591\u2588\u2588\u2557\u2591\u2591\u2591\u2591\u2591\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2591\u2591\u2591\u2588\u2588\u2557\u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2588\u2588\u2588\u2588\u2557\u2591\u2591\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2591\r\n\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2557\u2591\u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2551\u2591\u2591\u2591\u2591\u2591\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D\u2591\u2591\u2591\u2588\u2588\u2551\u2591\u2591\u2591\u2591\u2591\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D\u2591\r\n\u2588\u2588\u2551\u2591\u2591\u255A\u2550\u255D\u2588\u2588\u2551\u2591\u2591\u2588\u2588\u2551\u2588\u2588\u2554\u2588\u2588\u2557\u2588\u2588\u2551\u255A\u2588\u2588\u2588\u2588\u2588\u2557\u2591\u2588\u2588\u2551\u2591\u2591\u2588\u2588\u2551\u2588\u2588\u2551\u2591\u2591\u2591\u2591\u2591\u2588\u2588\u2588\u2588\u2588\u2557\u2591\u2591\u2591\u2591\u2591\u2588\u2588\u2551\u2591\u2591\u2591\u2591\u2591\u2588\u2588\u2551\u2591\u2591\u2588\u2588\u2551\u2588\u2588\u2551\u2591\u2591\u2588\u2588\u2557\u2591\r\n\u2588\u2588\u2551\u2591\u2591\u2588\u2588\u2557\u2588\u2588\u2551\u2591\u2591\u2588\u2588\u2551\u2588\u2588\u2551\u255A\u2588\u2588\u2588\u2588\u2551\u2591\u255A\u2550\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2551\u2591\u2591\u2588\u2588\u2551\u2588\u2588\u2551\u2591\u2591\u2591\u2591\u2591\u2588\u2588\u2554\u2550\u2550\u255D\u2591\u2591\u2591\u2591\u2591\u2588\u2588\u2551\u2591\u2591\u2591\u2591\u2591\u2588\u2588\u2551\u2591\u2591\u2588\u2588\u2551\u2588\u2588\u2551\u2591\u2591\u255A\u2588\u2588\u2557\r\n\u255A\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u255A\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2551\u2591\u255A\u2588\u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u255A\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u255A\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\r\n\u2591\u255A\u2550\u2550\u2550\u2550\u255D\u2591\u2591\u255A\u2550\u2550\u2550\u2550\u255D\u2591\u255A\u2550\u255D\u2591\u2591\u255A\u2550\u2550\u255D\u255A\u2550\u2550\u2550\u2550\u2550\u255D\u2591\u2591\u255A\u2550\u2550\u2550\u2550\u255D\u2591\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D\u255A\u2550\u255D\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D\u2591\u255A\u2550\u2550\u2550\u2550\u255D\u2591\u2591\u255A\u2550\u2550\u2550\u2550\u2550\u255D\u2591")
Result结果
░█████╗░░█████╗░███╗░░██╗░██████╗░█████╗░██╗░░░░░███████╗░░░██╗░░░░░░█████╗░░██████╗░
██╔══██╗██╔══██╗████╗░██║██╔════╝██╔══██╗██║░░░░░██╔════╝░░░██║░░░░░██╔══██╗██╔════╝░
██║░░╚═╝██║░░██║██╔██╗██║╚█████╗░██║░░██║██║░░░░░█████╗░░░░░██║░░░░░██║░░██║██║░░██╗░
██║░░██╗██║░░██║██║╚████║░╚═══██╗██║░░██║██║░░░░░██╔══╝░░░░░██║░░░░░██║░░██║██║░░╚██╗
╚█████╔╝╚█████╔╝██║░╚███║██████╔╝╚█████╔╝███████╗███████╗██╗███████╗╚█████╔╝╚██████╔╝
░╚════╝░░╚════╝░╚═╝░░╚══╝╚═════╝░░╚════╝░╚══════╝╚══════╝╚═╝╚══════╝░╚════╝░░╚═════╝░
( ) ( ) (_ ) /' ) ( ) | ( ) ( ) (_ ) /' ) ( ) | |
| |
| |
| _ _ |
_ _ | |
| |
| ( ___ _ _ _ __ | | | _ | /'
) | | |,__)/'___) /'_
( ___ _ _ _ __ | | | _ | /'
) | | |,__)/'___) /'_
) | | |,__)/'___) /'_
) | | |,__)/'___) /'_
)( ' )/' | | | | |( (_| | | | | | ( (___ ( (_| || | ( (_| | (_) (_)
) | | |,__)/'___) /'_
)( ' )/' | | | | |( (_| | | | | | ( (___ ( (_| || | ( (_| | (_) (_)
| | | | |( (_| | | | | | ( (___ ( (_| || | ( (_| | (_) (_)
| | | | |( (_| | | | | | ( (___ ( (_| || | ( (_| | (_) (_)
_ , )( )( ) \____)
_ , )( ) `_ , ) | | | | |( (_| | | | | | ( (___ ( (_| || | ( (_| | (_) (_)
_ , )( )( ) \____)
_ , )( ) `_ , )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.