Last active
January 1, 2018 04:01
-
-
Save Sam-Belliveau/cf9adf742ae278001abd64b54c24b464 to your computer and use it in GitHub Desktop.
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
#include <SFML/Graphics.hpp> | |
#include <iostream> | |
#include <fstream> | |
const char* tabel = "$@B\%8&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/\\|()1{}[]?-_+~<>i!lI;:,\"^`'. "; | |
const double length = 70.f; | |
const double mod = 256.f/length; | |
int main() | |
{ | |
std::string file; | |
std::cout << "Input Name Of A File: "; | |
std::cin >> file; | |
std::cout << std::endl; | |
sf::Image texture; | |
if (!texture.loadFromFile(file)) | |
{ | |
std::cout << "Uh Oh! " << file << " Was Not Found. :(" << std::endl; | |
return EXIT_FAILURE; | |
} else | |
{ | |
std::cout << "Thank You! " << file << " Was Found!" << std::endl; | |
} | |
std::ofstream output; | |
std::string outName = file + ".txt"; | |
output.open(outName); | |
if(!output.is_open()) | |
{ | |
std::cout << outName << " Was Not Able To Open. :("; | |
return EXIT_FAILURE; | |
} else | |
{ | |
std::cout << outName << " Was Able To Open!" << std::endl; | |
} | |
for(int y = 0; y < texture.getSize().y; y++) | |
{ | |
for(int x = 0; x < texture.getSize().x; x++) | |
{ | |
double r = texture.getPixel(x,y).r; | |
double g = texture.getPixel(x,y).g; | |
double b = texture.getPixel(x,y).b; | |
// According To Wiki Grayscale | |
// en.wikipedia.org/wiki/Grayscale | |
double avg = .2126f * r + | |
.7152f * g + | |
.0722f * b; | |
int color = (int)(avg/mod); | |
char print = tabel[color]; | |
output << print << print; | |
} | |
output << std::endl; | |
} | |
output.close(); | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment