fictionArt 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/bin/fictionArt +5 -0
- data/lib/fictionArt.rb +80 -0
- metadata +46 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 46138264dad7815d5065f3e923b8a2bf1f415fb9e6917f3ee09fa2e749adff89
|
4
|
+
data.tar.gz: 36d895e7199ac55e8211841477526a1f20f4ddfa51e91381f6881caf451e5e31
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 864be8d77f2f51ddf50205f53e5b336b47f6593a6f2323782429c26414f55307bf26c14e1ac1bdc7388f06b1bd3ad43431ced7a599f651c511837fefa56022f2
|
7
|
+
data.tar.gz: b2cbd29b9129581d72ac6df9874a8db79ec07e5a33b41deaaa52556197f606e6f78cecad79d506f52b5150c486851ed258a9f03896882a9de5c26840a5a49c8f
|
data/bin/fictionArt
ADDED
data/lib/fictionArt.rb
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'RMagick'
|
2
|
+
require 'uri'
|
3
|
+
require 'open-uri'
|
4
|
+
require 'rainbow'
|
5
|
+
require 'rainbow/ext/string'
|
6
|
+
|
7
|
+
class FictionArt
|
8
|
+
|
9
|
+
# Constructor function of FictionArt class
|
10
|
+
def initialize(text)
|
11
|
+
|
12
|
+
@image_chars ||= ' .~:+=o*x^%#@$MW'.chars.to_a
|
13
|
+
check = Dir.glob("../images/#{text}.png")
|
14
|
+
|
15
|
+
if check.length == 0
|
16
|
+
abort("Failure! Fictional Character not found")
|
17
|
+
else
|
18
|
+
open(check[0]) { |file| @data = file.read }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
# Create ascii Art of given fictional character
|
24
|
+
def createAscii(options = {})
|
25
|
+
|
26
|
+
options = {"width" => 80, "color" => false}.merge(options)
|
27
|
+
img = Magick::Image.from_blob(@data).first
|
28
|
+
|
29
|
+
width = options["width"]
|
30
|
+
scale = (width.to_f / img.columns)
|
31
|
+
height = ((img.rows * scale) / 2).to_i
|
32
|
+
border = "+#{'-' * width}+\n"
|
33
|
+
output = []
|
34
|
+
output << border
|
35
|
+
|
36
|
+
img.resize!(width, height)
|
37
|
+
color_image = img.dup if options["color"]
|
38
|
+
img = img.quantize(image_chars.length, Magick::GRAYColorspace).normalize
|
39
|
+
quantum_calc = Magick::QuantumRange / Magick::QuantumPixel.to_i
|
40
|
+
|
41
|
+
|
42
|
+
img.view(0, 0, width, height) do |view|
|
43
|
+
|
44
|
+
height.times do |i|
|
45
|
+
|
46
|
+
output << '|'
|
47
|
+
width.times do |j|
|
48
|
+
|
49
|
+
character = image_chars[view[i][j].red/quantum_calc]
|
50
|
+
|
51
|
+
if options["color"]
|
52
|
+
pix = color_image.pixel_color(j,i)
|
53
|
+
character = character.color(unified_rgb_value(pix.red), unified_rgb_value(pix.green), unified_rgb_value(pix.blue))
|
54
|
+
end
|
55
|
+
|
56
|
+
output << character
|
57
|
+
end
|
58
|
+
|
59
|
+
output << "\n"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
output << border
|
65
|
+
|
66
|
+
return output
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
# Converting into unified rgb value from 0-255
|
71
|
+
def unified_rgb_value(number)
|
72
|
+
if defined?(Magick::QuantumDepth)
|
73
|
+
return (Magick::QuantumDepth == 16) ? (number / 256) : number
|
74
|
+
else
|
75
|
+
return (Magick::QuantumRange == 65535) ? (number / 256) : number
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
end
|
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fictionArt
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Vaibhav Thakkar
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-06-28 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A gem to show Ascii Art of animated characters
|
14
|
+
email: vaibhav.thakkar.22.12.99@gmail.com
|
15
|
+
executables:
|
16
|
+
- fictionArt
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- bin/fictionArt
|
21
|
+
- lib/fictionArt.rb
|
22
|
+
homepage: http://rubygems.org/gems/fictionArt
|
23
|
+
licenses:
|
24
|
+
- MIT
|
25
|
+
metadata: {}
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubyforge_project:
|
42
|
+
rubygems_version: 2.7.6
|
43
|
+
signing_key:
|
44
|
+
specification_version: 4
|
45
|
+
summary: fictionArt
|
46
|
+
test_files: []
|