Write language name in 3D ASCII: Difference between revisions

Content added Content deleted
m (added a related task.)
(→‎{{header|Python}}: new implementation and better formatting)
Line 2,582: Line 2,582:


=={{header|Python}}==
=={{header|Python}}==
Again based on the Scala type idea of 'fleshing out' a 2D banner version.
<b>Implementation 1:</b> based on the Scala type idea of 'fleshing out' a 2D banner version.
<lang python>py = '''\
<lang python>py = '''\
##### # # ##### # # #### # #
##### # # ##### # # #### # #
Line 2,604: Line 2,604:
<<<> <<<> <<<> <<<> <<<> <<<<<<<<<<<<> <<<> <<<></pre>
<<<> <<<> <<<> <<<> <<<> <<<<<<<<<<<<> <<<> <<<></pre>


<b>Implementation 2:</b>
Another implementation:
<lang python>charWidth = 10
charHeight = 8
# char table is split into sets to prevent very long lines...
charSet1 = [
" /###### /####### /###### /###### /######## /######## /###### /## /##",
"| ##__ ##| ##__ ##| ##__ ##| ##__ ## | ##_____/| ##_____/| ##__ ##| ## | ##",
"| ## \ ##| ## \ ##| ## \__/| ## \ ##| ## | ## | ## \__/| ## | ##",
"| ########| ####### | ## | ## | ##| ########| ########| ## #####| ########",
"| ##__ ##| ##__ ##| ## | ## | ##| ##_____/| ##_____/| ##|_ ##| ##__ ##",
"| ## | ##| ## \ ##| ## /##| ## /##/| ## | ## | ## | ##| ## | ##",
"| ## | ##| #######/| ######/| ######/ | ########| ## | ######/| ## | ##",
"|__/ |__/|_______/ \______/ |______/ |________/|__/ \______/ |__/ |__/",
]


charSet2 = [
{{lines too long|Python|name 'table' should be split at least.
" /######## /## /## /## /## /### /### /## /## /###### /####### ",
"|__ ##__/ | ##| ## /##/| ## | ########| ### | ##| ##__ ##| ##__ ##",
" | ## | ##| ## /##/ | ## | ## ## ##| ####| ##| ## \ ##| ## \ ##",
" | ## | ##| #####/ | ## | ## ## ##| ## ## ##| ## | ##| #######/",
" | ## | ##| ## ## | ## | ## ## ##| ## ####| ## | ##| ##____/ ",
" | ## /## | ##| ##\ ## | ## | ##__/ ##| ##\ ###| ## | ##| ## ",
" /########\ ######/| ## \ ##| ########| ## | ##| ## \ ##| ######/| ## ",
"|________/ \______/ |__/ \__/|________/|__/ |__/|__/ \__/ \______/ |__/ ",
]


charSet3 = [
---- BTW, there is NO LIMIT on the number of characters in a single line of the source code written in Python.
" /###### /####### /###### /######## /## /## /## /## /## /## /## /##",
}}
"| ##__ ##| ##__ ##| ##__ ##|__ ##__/| ## | ##| ## | ##| ## | ##\ ## /##/",
"| ## \ ##| ## \ ##| ## \__/ | ## | ## | ##| ## | ##| ## ## ## \ ####/ ",
"| ## | ##| #######/ \ ###### | ## | ## | ##| ## | ##| ## ## ## \ ##/ ",
"| ## ## ##| ## ## \___ ## | ## | ## | ##| ## /##/| ## ## ## / #### ",
"| ##\ ###/| ##\ ## /## \ ## | ## | ## | ## \ ####/ | ######## / ## ## ",
"| #### ##| ## \ ##\ ######/ | ## | ######/ \ ##/ | ###| ###/ ## \ ##",
" \____\__/|__/ \__/ \______/ |__/ \______/ \__/ |___/|___/\__/ \__/",
]


charSet4 = [
<lang python>
" /## /## /######## /###### ",
l = 20
"\ ## /##/|____ ##/| ##__ ## ",
h = 11
" \ ####/ / ##/ | ## \ ## ",
" \ ##/ / ##/ |__//####/ ",
" | ## / ##/ | ##_/ ",
" | ## / ##/ |__/ ",
" | ## / ######## /## ",
" |__/ \________/ |__/ ",
]


# ...then the sets are combined back by barbequing them together!
table = [
charTable = [(charSet1[i] +
""" .----------------. .----------------. .----------------. .----------------. .----------------. .----------------. .----------------. .----------------. .----------------. .----------------. .----------------. .----------------. .----------------. .-----------------. .----------------. .----------------. .----------------. .----------------. .----------------. .----------------. .----------------. .----------------. .----------------. .----------------. .----------------. .----------------. .----------------. .----------------. """,
charSet2[i] +
"""| .--------------. || .--------------. || .--------------. || .--------------. || .--------------. || .--------------. || .--------------. || .--------------. || .--------------. || .--------------. || .--------------. || .--------------. || .--------------. || .--------------. || .--------------. || .--------------. || .--------------. || .--------------. || .--------------. || .--------------. || .--------------. || .--------------. || .--------------. || .--------------. || .--------------. || .--------------. || .--------------. || .--------------. |""",
charSet3[i] +
"""| | __ | || | ______ | || | ______ | || | ________ | || | _________ | || | _________ | || | ______ | || | ____ ____ | || | _____ | || | _____ | || | ___ ____ | || | _____ | || | ____ ____ | || | ____ _____ | || | ____ | || | ______ | || | ___ | || | _______ | || | _______ | || | _________ | || | _____ _____ | || | ____ ____ | || | _____ _____ | || | ____ ____ | || | ____ ____ | || | ________ | || | ______ | || | | |""",
charSet4[i]) for i in range(charHeight)]
"""| | / \ | || | |_ _ \ | || | .' ___ | | || | |_ ___ `. | || | |_ ___ | | || | |_ ___ | | || | .' ___ | | || | |_ || _| | || | |_ _| | || | |_ _| | || | |_ ||_ _| | || | |_ _| | || ||_ \ / _|| || ||_ \|_ _| | || | .' `. | || | |_ __ \ | || | .' '. | || | |_ __ \ | || | / ___ | | || | | _ _ | | || ||_ _||_ _|| || ||_ _| |_ _| | || ||_ _||_ _|| || | |_ _||_ _| | || | |_ _||_ _| | || | | __ _| | || | / _ __ `. | || | | |""",
"""| | / /\ \ | || | | |_) | | || | / .' \_| | || | | | `. \ | || | | |_ \_| | || | | |_ \_| | || | / .' \_| | || | | |__| | | || | | | | || | | | | || | | |_/ / | || | | | | || | | \/ | | || | | \ | | | || | / .--. \ | || | | |__) | | || | / .-. \ | || | | |__) | | || | | (__ \_| | || | |_/ | | \_| | || | | | | | | || | \ \ / / | || | | | /\ | | | || | \ \ / / | || | \ \ / / | || | |_/ / / | || | |_/____) | | || | | |""",
"""| | / ____ \ | || | | __'. | || | | | | || | | | | | | || | | _| _ | || | | _| | || | | | ____ | || | | __ | | || | | | | || | _ | | | || | | __'. | || | | | _ | || | | |\ /| | | || | | |\ \| | | || | | | | | | || | | ___/ | || | | | | | | || | | __ / | || | '.___`-. | || | | | | || | | ' ' | | || | \ \ / / | || | | |/ \| | | || | > `' < | || | \ \/ / | || | .'.' _ | || | / ___.' | || | | |""",
"""| | _/ / \ \_ | || | _| |__) | | || | \ `.___.'\ | || | _| |___.' / | || | _| |___/ | | || | _| |_ | || | \ `.___] _| | || | _| | | |_ | || | _| |_ | || | | |_' | | || | _| | \ \_ | || | _| |__/ | | || | _| |_\/_| |_ | || | _| |_\ |_ | || | \ `--' / | || | _| |_ | || | \ `-' \_ | || | _| | \ \_ | || | |`\____) | | || | _| |_ | || | \ `--' / | || | \ ' / | || | | /\ | | || | _/ /'`\ \_ | || | _| |_ | || | _/ /__/ | | || | |_| | || | | |""",
"""| ||____| |____|| || | |_______/ | || | `._____.' | || | |________.' | || | |_________| | || | |_____| | || | `._____.' | || | |____||____| | || | |_____| | || | `.___.' | || | |____||____| | || | |________| | || ||_____||_____|| || ||_____|\____| | || | `.____.' | || | |_____| | || | `.___.\__| | || | |____| |___| | || | |_______.' | || | |_____| | || | `.__.' | || | \_/ | || | |__/ \__| | || | |____||____| | || | |______| | || | |________| | || | (_) | || | | |""",
"""| | | || | | || | | || | | || | | || | | || | | || | | || | | || | | || | | || | | || | | || | | || | | || | | || | | || | | || | | || | | || | | || | | || | | || | | || | | || | | || | | || | | |""",
"""| '--------------' || '--------------' || '--------------' || '--------------' || '--------------' || '--------------' || '--------------' || '--------------' || '--------------' || '--------------' || '--------------' || '--------------' || '--------------' || '--------------' || '--------------' || '--------------' || '--------------' || '--------------' || '--------------' || '--------------' || '--------------' || '--------------' || '--------------' || '--------------' || '--------------' || '--------------' || '--------------' || '--------------' |""",
""" '----------------' '----------------' '----------------' '----------------' '----------------' '----------------' '----------------' '----------------' '----------------' '----------------' '----------------' '----------------' '----------------' '----------------' '----------------' '----------------' '----------------' '----------------' '----------------' '----------------' '----------------' '----------------' '----------------' '----------------' '----------------' '----------------' '----------------' '----------------' """
]


if __name__ == '__main__':
if __name__ == '__main__':
t = raw_input("Enter the text to convert :\n")
text = input("Enter the text to convert:\n")
if not t :
if not text:
t = "PYTHON"
text = "PYTHON"
for i in range(h):
for i in range(charHeight):
txt = ""
lineOut = ""
for char in t:
for chr in text:
# get dec value of T
# get value of character 'chr' in alphabet
if char.isalpha():
if chr.isalpha():
val = ord(char.upper()) - 65
val = ord(chr.upper()) - 65
elif char == " ":
elif chr == " ":
val= 27
val= 27
else:
else:
val = 26
val = 26
begin = val*l
beginStr = val * charWidth # begin string position of 3D letter
end = val*l + l
endStr = (val + 1) * charWidth # end string position of 3D letter
txt += table[i][begin:end]
lineOut += charTable[i][beginStr:endStr]
print txt
print(lineOut)</lang>
</lang>


{{out}}
{{out}}
<pre> /####### /## /## /######## /## /## /###### /## /##
<pre> .----------------. .----------------. .----------------. .----------------. .----------------. .-----------------.
| ##__ ##\ ## /##/|__ ##__/| ## | ##| ##__ ##| ### | ##
| .--------------. || .--------------. || .--------------. || .--------------. || .--------------. || .--------------. |
| | ______ | || | ____ ____ | || | _________ | || | ____ ____ | || | ____ | || | ____ _____ | |
| ## \ ## \ ####/ | ## | ## | ##| ## \ ##| ####| ##
| | |_ __ \ | || | |_ _||_ _| | || | | _ _ | | || | |_ || _| | || | .' `. | || ||_ \|_ _| | |
| #######/ \ ##/ | ## | ########| ## | ##| ## ## ##
| | | |__) | | || | \ \ / / | || | |_/ | | \_| | || | | |__| | | || | / .--. \ | || | | \ | | | |
| ##____/ | ## | ## | ##__ ##| ## | ##| ## ####
| | | ___/ | || | \ \/ / | || | | | | || | | __ | | || | | | | | | || | | |\ \| | | |
| ## | ## | ## | ## | ##| ## | ##| ##\ ###
| | _| |_ | || | _| |_ | || | _| |_ | || | _| | | |_ | || | \ `--' / | || | _| |_\ |_ | |
| ## | ## | ## | ## | ##| ######/| ## \ ##
| | |_____| | || | |______| | || | |_____| | || | |____||____| | || | `.____.' | || ||_____|\____| | |
|__/ |__/ |__/ |__/ |__/ \______/ |__/ \__/</pre>
| | | || | | || | | || | | || | | || | | |
| '--------------' || '--------------' || '--------------' || '--------------' || '--------------' || '--------------' |
'----------------' '----------------' '----------------' '----------------' '----------------' '----------------' </pre>


A more general solution that scrapes http://www.network-science.de/ascii for the ascii art.
<b>Implementation 3:</b> a more general solution that scrapes http://www.network-science.de/ascii for the ASCII art.
<lang python>import requests
<lang python>import requests
import html
import html