Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. # frozen_string_literal: true
  2.  
  3. require 'chunky_png'
  4.  
  5. ascii = <<~ASCII
  6. @@@@@@ @@@@@@
  7. @@@@@@@@@@ @@@@@@@@@@
  8. @@@@@@@@@@@@@@ @@@@@@@@@@@@@@
  9. @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  10. @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  11. @@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@
  12. @@@@@@@@@@@@ @@@@@@@@@@@@
  13. @@@@@@@@@@ @@@@@@@@@@
  14. @@@@@@@@@@@ @@@@@@@@@@@
  15. @@@@@@@@@@@@ @@@@@@@@@@@@
  16. @@@@@@@@@@@@@ @@@@@@@@@@@@@
  17. @@@@@@@@@@@@@@ @@@@@@@@@@@@@@
  18. @@@@@@@@@@@@@ @@@@@@@@@@@@@
  19. @@@@@@@@@@@@@@@@@@@@@
  20. @@@@@@@@@@@@@@@
  21. @@@@@@@@@@@
  22. @@@@@@@
  23. @@@
  24. @
  25. ASCII
  26.  
  27. lines = ascii.lines
  28. horizontal = lines.max_by(&:size).size
  29. vertical = lines.size * 2
  30. red = [255, 0, 0]
  31. alpha = 255
  32. filename = 'ruby.png'
  33. png = ChunkyPNG::Image.new(horizontal, vertical, ChunkyPNG::Color::TRANSPARENT)
  34.  
  35. lines.flat_map { |line| [line, line] }.each_with_index do |line, y|
  36. line.each_char.with_index do |char, x|
  37. png[x, y] = ChunkyPNG::Color.rgba(*red, alpha) if char != ' '
  38. end
  39. end
  40.  
  41. png.save(filename, interlace: true)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement