fictionArt 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3cee34142b88b8607296f7118a43b29379f8355bf175642c61f6641d5a21603e
4
- data.tar.gz: e764306950aa1514f17d198fa5bd3fe15e11f227098cdc1905c2fa15ca9752bd
3
+ metadata.gz: d357bc789da33eb33dcd917923c64003638d85eefde0946c1784f499ab81b30d
4
+ data.tar.gz: b84d0d52a4c3b2b63884452164575da8778f182c27d249b1bbeed9db3234fcf9
5
5
  SHA512:
6
- metadata.gz: f9ab3239920659970390f4f73c886ea3267cfabece737eb8375803ae11949815a0cb512394d197b9f4ea77115b018092ba3f85c2743d29afa1f3b19876f59494
7
- data.tar.gz: 2133f228d5d8cd1846d76b7450d3abd05cfc19a0035aca682adf09dc15cc5972f92f2449f7d9f043db1ec4df42485a8d654e55253d2454bf02d0cbbdbd73900c
6
+ metadata.gz: 18617faceab3509c2bb5e6914b1e51c6211d786ee730738ea5ab4910814995f8eb8cb5c23c2484c1f73a99438c1b2c8e7b4620d94a3bf3c0641072ee1de45e35
7
+ data.tar.gz: b9816365b2d7066c629be966e9c90f14b08da5c6e7954fa8de77a66ac49707180d8dc67c93173e1ee69ed98de70b9c32c4965fe6e2f71a9028ea04797fe4f928
@@ -0,0 +1,48 @@
1
+ # fictionArt
2
+ A command line tool written in ruby that displays ascii art of famous animated fictional characters.
3
+
4
+ ## Requirements
5
+ ```
6
+ => Homebrew (for macOS)
7
+ => ruby version >= 1.8.6 (pre-installed on macOS, can be easily installed on linux)
8
+ => ImageMagick library (will be installed in next section)
9
+ ```
10
+
11
+ ## Installation
12
+
13
+ ### Linux
14
+
15
+ **Run the following commands after (without the '$' sign) ruby has been installed succesfully**
16
+ ```
17
+ $ echo "export GEM_HOME=$HOME/.gem" >> ~/.bashrc
18
+ $ echo "export GEM_PATH=$HOME/.gem" >> ~/.bashrc
19
+ $ echo "export PATH=$PATH:~/.gem/bin" >> ~/.bashrc
20
+ $ source ~/.bashrc
21
+ $ sudo apt-get install imagemagick libmagickwand-dev
22
+ $ gem install fictionArt
23
+ ```
24
+
25
+ ### MacOS
26
+
27
+ **Run the following commands (without the '$' sign) after ruby has been installed succesfully**
28
+ ```
29
+ $ echo "export GEM_HOME=$HOME/.gem" >> ~/.bash_profile
30
+ $ echo "export GEM_PATH=$HOME/.gem" >> ~/.bash_profile
31
+ $ echo "export PATH=$PATH:~/.gem/bin" >> ~/.bash_profile
32
+ $ source ~/.bash_profile
33
+ $ brew install imagemagick@6 && brew link imagemagick@6 --force
34
+ $ gem install fictionArt
35
+ ```
36
+
37
+ ### Usage
38
+ **Example**
39
+ ```
40
+ $ fictionArt ironman
41
+ ```
42
+ **Output**
43
+ ![image](https://github.com/vaithak/fictionArt/blob/master/example_image.png)
44
+
45
+ ### Help
46
+ ```
47
+ $ fictionArt -h
48
+ ```
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,123 @@
1
+ require 'RMagick'
2
+ require 'uri'
3
+ require 'open-uri'
4
+ require 'rainbow'
5
+ require 'rainbow/ext/string'
6
+
7
+ class FictionArt
8
+
9
+ attr_accessor :image_chars
10
+ attr_accessor :status # for tests
11
+
12
+ # Constructor function of FictionArt class
13
+ def initialize(text = "nothing")
14
+
15
+ @image_chars ||= ' .~:+=o*x^%#@'.chars.to_a
16
+ check = Dir.glob("#{__dir__}/../images/#{text}.jpg")
17
+
18
+ if check.length == 0
19
+ if text == "nothing"
20
+ @status = false # for tests
21
+ elsif text.nil?
22
+ @status = false # for tests
23
+ abort("Nothing inputted")
24
+ else
25
+ @status = false # for tests
26
+ puts
27
+ check_possible(text)
28
+ end
29
+ else
30
+ open(check[0]) { |file| @data = file.read }
31
+ @status = true # for tests
32
+ end
33
+
34
+ end
35
+
36
+
37
+ # Create ascii Art of given fictional character
38
+ def createAscii(options = {})
39
+ if @status == true
40
+ options = {"width" => 90, "color" => true}.merge(options)
41
+ img = Magick::Image.from_blob(@data).first
42
+ width = options["width"]
43
+ scale = (width.to_f / img.columns)
44
+
45
+ height = ((img.rows * scale) / 2).to_i
46
+ # puts height
47
+ if height >= 100
48
+ height = 80
49
+ end
50
+
51
+ border = "+#{'-' * width}+\n"
52
+ output = border.dup
53
+
54
+ img.resize!(width, height)
55
+ color_image = img.dup if options["color"]
56
+ img = img.quantize(@image_chars.length, Magick::GRAYColorspace).normalize
57
+ quantum_calc = Magick::QuantumRange / (@image_chars.length - 1)
58
+
59
+
60
+ img.view(0, 0, width, height) do |view|
61
+
62
+ height.times do |i|
63
+
64
+ output << '|'
65
+ width.times do |j|
66
+
67
+ character = @image_chars[view[i][j].red/quantum_calc]
68
+
69
+ if options["color"]
70
+ pix = color_image.pixel_color(j,i)
71
+ character = character.color(unified_rgb_value(pix.red), unified_rgb_value(pix.green), unified_rgb_value(pix.blue))
72
+ end
73
+
74
+ output << character
75
+ end
76
+
77
+ output << "|\n"
78
+ end
79
+ end
80
+
81
+
82
+ output << border
83
+ return output
84
+ end
85
+ end
86
+
87
+
88
+ # Converting into unified rgb value from 0-255
89
+ def unified_rgb_value(number)
90
+ if defined?(Magick::QuantumDepth)
91
+ return (Magick::QuantumDepth == 16) ? (number / 256) : number
92
+ else
93
+ return (Magick::QuantumRange == 65535) ? (number / 256) : number
94
+ end
95
+ end
96
+
97
+
98
+ # Listing all currently possible characters
99
+ def list_all
100
+ list = Dir.glob("#{__dir__}/../images/*.jpg")
101
+ list.each do |character|
102
+ puts character[/.*images\/(.*).jpg/,1]
103
+ end
104
+ end
105
+
106
+
107
+ # Checking matching characters from character inputted
108
+ def check_possible(text)
109
+ puts "Possible Characters:"
110
+ list = Dir.glob("#{__dir__}/../images/*.jpg")
111
+
112
+ list.each do |character|
113
+ character = character[/.*images\/(.*).jpg/,1]
114
+ if character.downcase.include? text.downcase
115
+ puts character
116
+ elsif text.downcase.include? character.downcase
117
+ puts character
118
+ end
119
+ end
120
+
121
+ end
122
+
123
+ 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: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vaibhav Thakkar
@@ -45,7 +45,43 @@ executables:
45
45
  extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
+ - README.md
48
49
  - bin/fictionArt
50
+ - images/ash_pokemon.jpg
51
+ - images/batman.jpg
52
+ - images/baymax.jpg
53
+ - images/bulbasaur.jpg
54
+ - images/captain_america.jpg
55
+ - images/charizard.jpg
56
+ - images/charmander.jpg
57
+ - images/doctor_strange.jpg
58
+ - images/doofenshmirtz.jpg
59
+ - images/doraemon.jpg
60
+ - images/ferb.jpg
61
+ - images/gian.jpg
62
+ - images/goku.jpg
63
+ - images/hawkeye.jpg
64
+ - images/hulk.jpg
65
+ - images/humungousaur.jpg
66
+ - images/ironman.jpg
67
+ - images/joker.jpg
68
+ - images/krrish.jpg
69
+ - images/nobita.jpg
70
+ - images/oggy.jpg
71
+ - images/perry.jpg
72
+ - images/phineas.jpg
73
+ - images/pikachu.jpg
74
+ - images/shizuka.jpg
75
+ - images/spiderman.jpg
76
+ - images/squirtle.jpg
77
+ - images/suneo.jpg
78
+ - images/superman.jpg
79
+ - images/thanos.jpg
80
+ - images/thor.jpg
81
+ - images/tom_and_jerry.jpg
82
+ - images/vegeta.jpg
83
+ - images/vision.jpg
84
+ - lib/fictionArt.rb
49
85
  homepage: https://github.com/vaithak/fictionArt
50
86
  licenses:
51
87
  - MIT