Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #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;
- }
Add Comment
Please, Sign In to add comment