Last active
October 1, 2016 16:30
-
-
Save papodaca/ed5b81e9394796f2cefd18ee78aaa56e to your computer and use it in GitHub Desktop.
ASCII WEB ART
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { | |
background-color: black; | |
} | |
pre { | |
font-size:18px; | |
line-height: 20px; | |
font-family: monospace; | |
} | |
span { | |
height:20px; | |
} | |
.black, .dark-black { | |
color: #333; | |
} | |
.dark-blue { | |
color: #0000AA; | |
} | |
.dark-green { | |
color: #55FF55; | |
} | |
.dark-cyan { | |
color: #00AAAA; | |
} | |
.dark-red { | |
color: #AA0000; | |
} | |
.dark-magenta { | |
color: #AA00AA; | |
} | |
.brown { | |
color: #AA5500; | |
} | |
.gray { | |
color: #AAA; | |
} | |
.dark-gray { | |
color: #555; | |
} | |
.blue { | |
color: #5555FF; | |
} | |
.green { | |
color: #00AA00; | |
} | |
.cyan { | |
color: #55FFFF; | |
} | |
.red { | |
color: #FF5555; | |
} | |
.magenta { | |
color: #FF55FF; | |
} | |
.yellow { | |
color: #FFFF55; | |
} | |
.white { | |
color: #FFF; | |
} | |
.bg-black, .bg-dark-black { | |
background-color: #333; | |
} | |
.bg-dark-blue { | |
background-color: #0000AA; | |
} | |
.bg-dark-green { | |
background-color: #00AA00; | |
} | |
.bg-dark-cyan { | |
background-color: #00AAAA; | |
} | |
.bg-dark-red { | |
background-color: #AA0000; | |
} | |
.bg-dark-magenta { | |
background-color: #AA00AA; | |
} | |
.bg-brown { | |
background-color: #AA5500; | |
} | |
.bg-gray { | |
background-color: #AAA; | |
} | |
.bg-dark-gray { | |
background-color: #555; | |
} | |
.bg-blue { | |
background-color: #5555FF; | |
} | |
.bg-green { | |
background-color: #55FF55; | |
} | |
.bg-cyan { | |
background-color: #55FFFF; | |
} | |
.bg-red { | |
background-color: #FF5555; | |
} | |
.bg-magenta { | |
background-color: #FF55FF; | |
} | |
.bg-yellow { | |
background-color: #FFFF55; | |
} | |
.bg-white { | |
background-color: #FFF; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Copyright © Ethan Apodaca 2016 | |
[email protected] | |
usage: | |
g++ -std=c++11 ascii2html.cpp -o ascii2html | |
iconv -f 437 TOWER.ANS | ./ascii2html > tower.html | |
Add output to webpage | |
*/ | |
#include <iostream> | |
#include <sstream> | |
#include <string> | |
#include <algorithm> | |
using namespace std; | |
// For esc-codes details: http://ascii-table.com/ansi-escape-sequences.php | |
char enders[14] = {'H', 'f', 'A', 'B', 'C', 'D', 's', 'u', 'J', 'K', 'm', 'h', 'l', 'p'}; | |
enum color { | |
BLACK = 30, | |
RED = 31, | |
GREEN = 32, | |
YELLOW = 33, | |
BLUE = 34, | |
MAGENTA = 35, | |
CYAN = 36, | |
WHITE = 37 | |
}; | |
#define idName(x) case x: return #x | |
string ColorToName(int id) { | |
switch(id) { | |
idName(BLACK); | |
idName(RED); | |
idName(GREEN); | |
idName(YELLOW); | |
idName(BLUE); | |
idName(MAGENTA); | |
idName(CYAN); | |
idName(WHITE); | |
default: return NULL; | |
} | |
} | |
bool isEnder(char character) { | |
for(int ii = 0; ii< 14; ii++) { | |
if(enders[ii] == character) { | |
return true; | |
} | |
} | |
return false; | |
} | |
bool firstSpan = true; | |
bool bold = false; | |
int colorCode = -1; | |
int bgColorCode = -1; | |
string generateSpan() { | |
string classes = ""; | |
if(colorCode != -1) { | |
classes = (bold?"dark-":"") + ColorToName(colorCode); | |
} | |
if(bgColorCode != -1) { | |
classes = classes + " bg-" + (bold?"dark-":"") + ColorToName(bgColorCode); | |
} | |
transform(classes.begin(), classes.end(), classes.begin(), ::tolower); | |
return "<span class=\"" + classes + "\">"; | |
} | |
void processCode(string code) { | |
istringstream ss(code); | |
string part; | |
while(std::getline(ss, part, ';')) { | |
int numCode = std::stoi(part.c_str()); | |
if(numCode == 0) { | |
bold = false; | |
bgColorCode = -1; | |
colorCode = -1; | |
} else if(numCode == 1) { | |
bold = true; | |
} else if(numCode>=30 && numCode <=37) { | |
colorCode = numCode; | |
} else if(numCode>=40 && numCode <=47) { | |
bgColorCode = numCode - 10; | |
} | |
} | |
if(!firstSpan) { | |
cout<< "</span>"; | |
} else { | |
firstSpan = false; | |
} | |
cout << generateSpan(); | |
} | |
int main() { | |
for (string line; getline(cin, line);) { | |
for (auto ii = 0 ; ii < line.length(); ii++) { | |
char character = line[ii]; | |
if(character == '\x1b') { | |
string code = ""; | |
while(!isEnder(character)) { | |
character = line[++ii]; | |
if(character != '[' && !isEnder(character)) { | |
code = code + character; | |
} | |
if(isEnder(character)) { | |
if(character == 'm') { | |
processCode(code); | |
} else if(character == 'C') { | |
cout << "</span>"; | |
for(auto ii=std::stoi(code.c_str());ii>0;ii--) { | |
cout << " "; | |
} | |
cout << generateSpan(); | |
} | |
} | |
} | |
} else { | |
if(character == ' ') { | |
cout << "</span> " << generateSpan(); | |
} else { | |
cout << character; | |
} | |
} | |
} | |
} | |
cout << "</span>"; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[?7h[40m[2J[0;1;32mワワワワワワワ ワワ [30mワ [32mワワ ワワワワワワワ | |
[30mワ [32;42mロロ[30;40mーワワ [32;42mイ゚[1C[30;40m゚ [32;42mイロ[1Cイ゚[0;32mワワ [1m゚゚ | |
[30mイ [32;42mイ[0;32mイ [1;30;42mイ[40mロ [32;42mー[0;32mイ[1m゚゚゚[42mア゚[1Cア[0;32mイワ[1;30mー [32;42mイ゚[40m | |
[30m゚ [0;32m゚゚[1;30mー゚゚ [0;32m゚゚ [1;30m゚ [32;42mー[0;32mロ ゚゚゚゚゚゚ | |
[1mワワワワワワワ ワワワワワワワ ワワ ワワ ロロ ワワワワワワワ ワワワワワワ | |
[30mワ [32;42mロロ[30;40mーワワ [32;42mイ゚[1C[30;40mワ [32;42mロイ[1Cロロ[30;40mーロ [32;42mイロ[1C[30;40mイ [32;42mロロ[1Cイ゚[0;32mワワ [1m゚゚ [42mロロ[30;40mーワ [32;42mイロ[40m | |
[30mイ [32;42mイ[0;32mイ [1;30;42mイ[40mロ [32;42mー[0;32mイワ[1;30m゚ [32;42mイ [1Cイ[0;32mイ [1;30m゚[0;32mワ[1;42mア゚[1C[30;40m゚[0;32mワ[1;42mイ[0;32mイ [1;42mア[0;32mイワ[1;30mー [32;42mイ゚[1Cイ[0;32mイ [1;30mイ [32;42mー゚[40m | |
[30m゚ [0;32m゚゚[1;30mー゚゚ [0;32m゚゚゚゚゚゚ ゚゚゚゚゚゚[1;30mワ[0;32m゚゚゚゚ ゚゚゚゚゚゚ ゚゚[1;30mー |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment