fictionArt 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/fictionArt +53 -1
- data/lib/fictionArt.rb +88 -46
- metadata +34 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 05d4049a0beeb475fdc8905ec826567c160585fdd25a7a37d306d63ca2b77f28
|
4
|
+
data.tar.gz: 5d6ad10595b6510fde9a4fb3644e520cc6cad88e6e58bfb59f2976d44d8e5efd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8cec36acd896e9fbdeeabe93cac79b0f625227d29c746b9ad1299527b1b72f812d669f5ffee5645e7b027f550a667de245b0e010e3d4caa5cf733dc785a2bc27
|
7
|
+
data.tar.gz: f3c4ffefb3430e081a582eea0ea6eae140b6c5c92037c8f82b92f79f36fd9233f6ded30673e1e8effd982578250f5c9e3ccce63a36aa973c4ed56d8fac7a618d
|
data/bin/fictionArt
CHANGED
@@ -1,5 +1,57 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require 'fictionArt'
|
4
|
+
require 'optparse'
|
4
5
|
|
5
|
-
|
6
|
+
options = {}
|
7
|
+
invert_chars = false
|
8
|
+
list = false
|
9
|
+
|
10
|
+
opt_parser = OptionParser.new do |opts|
|
11
|
+
opts.banner = 'Usage: fictionArt [options] <name_of_a_fictional_character>'
|
12
|
+
|
13
|
+
opts.on('-w', '--width WIDTH', 'Width of the finished Ascii Art (Default: 100)') do |width|
|
14
|
+
options["width"] = width.to_i
|
15
|
+
end
|
16
|
+
|
17
|
+
opts.on('-c', '--color', 'Switch to use colored terminal output (Default: true)') do
|
18
|
+
options["color"] = true
|
19
|
+
end
|
20
|
+
|
21
|
+
opts.on('-i', '--invert-chars', 'Invert the character map. Depending on your terminal and image this can make the image clearer (or a lot worse)') do
|
22
|
+
invert_chars = true
|
23
|
+
end
|
24
|
+
|
25
|
+
opts.on('-l', '--list', 'List all currently possible fictional characters') do
|
26
|
+
list = true
|
27
|
+
end
|
28
|
+
|
29
|
+
opts.on_tail("-h", "--help", "Show this message") do
|
30
|
+
puts opts
|
31
|
+
exit
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
begin
|
37
|
+
opt_parser.parse!
|
38
|
+
rescue OptionParser::MissingArgument => e
|
39
|
+
puts "ERROR: #{e.message.capitalize}\n#{opt_parser}"
|
40
|
+
exit
|
41
|
+
end
|
42
|
+
|
43
|
+
if ARGV.length == 0
|
44
|
+
if list == false
|
45
|
+
puts "ERROR: You must specify a name of a character \n#{opt_parser}"
|
46
|
+
exit
|
47
|
+
else
|
48
|
+
fiction = FictionArt.new
|
49
|
+
fiction.list_all()
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
fiction = FictionArt.new(ARGV[0])
|
54
|
+
|
55
|
+
fiction.image_chars = fiction.image_chars.reverse if invert_chars
|
56
|
+
|
57
|
+
puts fiction.createAscii(options)
|
data/lib/fictionArt.rb
CHANGED
@@ -6,64 +6,81 @@ require 'rainbow/ext/string'
|
|
6
6
|
|
7
7
|
class FictionArt
|
8
8
|
|
9
|
+
attr_accessor :image_chars
|
10
|
+
attr_accessor :status # for tests
|
11
|
+
|
9
12
|
# Constructor function of FictionArt class
|
10
|
-
def initialize(text)
|
13
|
+
def initialize(text = "nothing")
|
11
14
|
|
12
|
-
@image_chars ||= ' .~:+=o*x
|
13
|
-
check = Dir.glob("
|
15
|
+
@image_chars ||= ' .~:+=o*x^%#@'.chars.to_a
|
16
|
+
check = Dir.glob("images/#{text}.jpg")
|
14
17
|
|
15
18
|
if check.length == 0
|
16
|
-
|
19
|
+
if text == "nothing"
|
20
|
+
@status = false # for tests
|
21
|
+
elsif text.length == 0
|
22
|
+
@status = false # for tests
|
23
|
+
abort("Nothing inputted")
|
24
|
+
else
|
25
|
+
@status = false # for tests
|
26
|
+
check_possible(text)
|
27
|
+
end
|
17
28
|
else
|
18
29
|
open(check[0]) { |file| @data = file.read }
|
30
|
+
@status = true # for tests
|
19
31
|
end
|
32
|
+
|
20
33
|
end
|
21
34
|
|
22
35
|
|
23
36
|
# Create ascii Art of given fictional character
|
24
37
|
def createAscii(options = {})
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
38
|
+
if @status == true
|
39
|
+
options = {"width" => 90, "color" => true}.merge(options)
|
40
|
+
img = Magick::Image.from_blob(@data).first
|
41
|
+
width = options["width"]
|
42
|
+
scale = (width.to_f / img.columns)
|
43
|
+
|
44
|
+
height = ((img.rows * scale) / 2).to_i
|
45
|
+
# puts height
|
46
|
+
if height >= 100
|
47
|
+
height = 80
|
48
|
+
end
|
49
|
+
|
50
|
+
border = "+#{'-' * width}+\n"
|
51
|
+
output = border.dup
|
52
|
+
|
53
|
+
img.resize!(width, height)
|
54
|
+
color_image = img.dup if options["color"]
|
55
|
+
img = img.quantize(@image_chars.length, Magick::GRAYColorspace).normalize
|
56
|
+
quantum_calc = Magick::QuantumRange / (@image_chars.length - 1)
|
57
|
+
|
58
|
+
|
59
|
+
img.view(0, 0, width, height) do |view|
|
60
|
+
|
61
|
+
height.times do |i|
|
62
|
+
|
63
|
+
output << '|'
|
64
|
+
width.times do |j|
|
65
|
+
|
66
|
+
character = @image_chars[view[i][j].red/quantum_calc]
|
67
|
+
|
68
|
+
if options["color"]
|
69
|
+
pix = color_image.pixel_color(j,i)
|
70
|
+
character = character.color(unified_rgb_value(pix.red), unified_rgb_value(pix.green), unified_rgb_value(pix.blue))
|
71
|
+
end
|
72
|
+
|
73
|
+
output << character
|
74
|
+
end
|
75
|
+
|
76
|
+
output << "|\n"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
|
81
|
+
output << border
|
82
|
+
return output
|
83
|
+
end
|
67
84
|
end
|
68
85
|
|
69
86
|
|
@@ -77,4 +94,29 @@ class FictionArt
|
|
77
94
|
end
|
78
95
|
|
79
96
|
|
97
|
+
# Listing all currently possible characters
|
98
|
+
def list_all
|
99
|
+
list = Dir.glob("images/*.jpg")
|
100
|
+
list.each do |character|
|
101
|
+
puts character.chomp(".jpg").slice(7..-1)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
|
106
|
+
# Checking matching characters from character inputted
|
107
|
+
def check_possible(text)
|
108
|
+
puts "Possible Characters:"
|
109
|
+
list = Dir.glob("images/*.jpg")
|
110
|
+
|
111
|
+
list.each do |character|
|
112
|
+
character = character.chomp(".jpg").slice(7..-1)
|
113
|
+
if character.downcase.include? text.downcase
|
114
|
+
puts character
|
115
|
+
elsif text.downcase.include? character.downcase
|
116
|
+
puts character
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
121
|
+
|
80
122
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fictionArt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vaibhav Thakkar
|
@@ -9,8 +9,36 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
date: 2018-06-28 00:00:00.000000000 Z
|
12
|
-
dependencies:
|
13
|
-
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rmagick
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.13.4
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.13.4
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rainbow
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.0.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.0.0
|
41
|
+
description: A gem to show Ascii Art of fictional animated characters
|
14
42
|
email: vaibhav.thakkar.22.12.99@gmail.com
|
15
43
|
executables:
|
16
44
|
- fictionArt
|
@@ -22,7 +50,8 @@ files:
|
|
22
50
|
homepage: http://rubygems.org/gems/fictionArt
|
23
51
|
licenses:
|
24
52
|
- MIT
|
25
|
-
metadata:
|
53
|
+
metadata:
|
54
|
+
source_code_uri: https://github.com/vaithak/fictionArt
|
26
55
|
post_install_message:
|
27
56
|
rdoc_options: []
|
28
57
|
require_paths:
|
@@ -42,5 +71,5 @@ rubyforge_project:
|
|
42
71
|
rubygems_version: 2.7.6
|
43
72
|
signing_key:
|
44
73
|
specification_version: 4
|
45
|
-
summary:
|
74
|
+
summary: Display ascii art of animated fictional characters on your terminal
|
46
75
|
test_files: []
|