Guest User

Untitled

a guest
Jan 7th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. #include <SFML/Graphics.hpp>
  2. #include <iostream>
  3. #include <fstream>
  4.  
  5. const char* tabel = "$@B\%8&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/\\|()1{}[]?-_+~<>i!lI;:,\"^`'. ";
  6. const double length = 70.f;
  7. const double mod = 256.f/length;
  8.  
  9. int main()
  10. {
  11. std::string file;
  12. std::cout << "Input Name Of A File: ";
  13. std::cin >> file;
  14. std::cout << std::endl;
  15.  
  16. sf::Image texture;
  17. if (!texture.loadFromFile(file))
  18. {
  19. std::cout << "Uh Oh! " << file << " Was Not Found. :(" << std::endl;
  20. return EXIT_FAILURE;
  21. } else
  22. {
  23. std::cout << "Thank You! " << file << " Was Found!" << std::endl;
  24. }
  25.  
  26. std::ofstream output;
  27. std::string outName = file + ".txt";
  28. output.open(outName);
  29. if(!output.is_open())
  30. {
  31. std::cout << outName << " Was Not Able To Open. :(";
  32. return EXIT_FAILURE;
  33. } else
  34. {
  35. std::cout << outName << " Was Able To Open!" << std::endl;
  36. }
  37.  
  38. for(int y = 0; y < texture.getSize().y; y++)
  39. {
  40. for(int x = 0; x < texture.getSize().x; x++)
  41. {
  42. double r = texture.getPixel(x,y).r;
  43. double g = texture.getPixel(x,y).g;
  44. double b = texture.getPixel(x,y).b;
  45.  
  46. // According To Wiki Grayscale
  47. // en.wikipedia.org/wiki/Grayscale
  48. double avg = .2126f * r +
  49. .7152f * g +
  50. .0722f * b;
  51.  
  52. int color = (int)(avg/mod);
  53. char print = tabel[color];
  54.  
  55. output << print << print;
  56. }
  57. output << std::endl;
  58. }
  59.  
  60. output.close();
  61.  
  62. return EXIT_SUCCESS;
  63. }
Add Comment
Please, Sign In to add comment