aaq 0.1.1 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop_todo.yml +6 -6
- data/Dockerfile +13 -0
- data/README.md +15 -15
- data/aaq.gemspec +2 -2
- data/exe/aaq +28 -4
- data/lib/aaq/version.rb +1 -1
- data/lib/aaq.rb +15 -12
- metadata +12 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 57bbcba5eec32436dae30fe60a35aca0aff4d8fecf1fdd4931d3649233eaa292
|
4
|
+
data.tar.gz: ee4461f18cbbc7ea29470bad73c8083963a9e8db8a8b5799f0345964cda4ce3c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bf280853a4c201fbe2b3aaff20b11bc263d2fec1116a0d6a5f8352983a17b056e4fe8a4580e7f46b7864ccd786e94cd7b67e4751f7868df38204e6d4dd5d21ad
|
7
|
+
data.tar.gz: 0d0addfad1db5c00cd1161322591e388f7f7b2192e593a130fcdaba454cec2349c9937e727a87a99ca40f4d0ef47ae19608287b97c7e9d946f04700b79cb8acb
|
data/.rubocop_todo.yml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on 2018-
|
3
|
+
# on 2018-11-10 23:33:14 +0900 using RuboCop version 0.60.0.
|
4
4
|
# The point is for the user to remove these configuration records
|
5
5
|
# one by one as the offenses are removed from the code base.
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
@@ -14,7 +14,7 @@ Metrics/AbcSize:
|
|
14
14
|
# Configuration parameters: CountComments, ExcludedMethods.
|
15
15
|
# ExcludedMethods: refine
|
16
16
|
Metrics/BlockLength:
|
17
|
-
Max:
|
17
|
+
Max: 61
|
18
18
|
|
19
19
|
# Offense count: 1
|
20
20
|
# Configuration parameters: CountComments.
|
@@ -22,21 +22,21 @@ Metrics/ClassLength:
|
|
22
22
|
Max: 118
|
23
23
|
|
24
24
|
# Offense count: 2
|
25
|
-
# Configuration parameters: CountComments.
|
25
|
+
# Configuration parameters: CountComments, ExcludedMethods.
|
26
26
|
Metrics/MethodLength:
|
27
27
|
Max: 24
|
28
28
|
|
29
29
|
# Offense count: 4
|
30
30
|
# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
|
31
|
-
# AllowedNames: io, id, to, by, on, in, at
|
32
|
-
Naming/
|
31
|
+
# AllowedNames: io, id, to, by, on, in, at, ip, db
|
32
|
+
Naming/MethodParameterName:
|
33
33
|
Exclude:
|
34
34
|
- 'lib/aaq.rb'
|
35
35
|
|
36
36
|
# Offense count: 1
|
37
37
|
Security/Eval:
|
38
38
|
Exclude:
|
39
|
-
- '
|
39
|
+
- 'exe/aaq'
|
40
40
|
|
41
41
|
# Offense count: 1
|
42
42
|
Security/Open:
|
data/Dockerfile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
FROM ruby:2.7.1-alpine
|
2
|
+
|
3
|
+
ARG AAQ_VERSION="0.1.4"
|
4
|
+
|
5
|
+
RUN apk add --no-cache --virtual=build-deps gcc libc-dev make pkgconfig \
|
6
|
+
&& apk add --no-cache imagemagick6 imagemagick6-dev imagemagick6-libs \
|
7
|
+
&& gem install aaq -v ${AAQ_VERSION} \
|
8
|
+
&& apk del --no-cache build-deps
|
9
|
+
|
10
|
+
WORKDIR /root
|
11
|
+
|
12
|
+
CMD ["echo", "[usage]: docker run --rm -v $(pwd):/root yskoht/aaq aaq [image] [--color]"]
|
13
|
+
|
data/README.md
CHANGED
@@ -1,26 +1,26 @@
|
|
1
|
+
|
1
2
|
# AAQ - Ascii Art Quine
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
curl -O https://github-media-downloads.s3.amazonaws.com/Octocats.zip && unzip Octocats.zip
|
6
|
-
aaq Octocat/Octocat.png --color
|
7
|
-
```
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/aaq.svg)](https://badge.fury.io/rb/aaq)
|
5
|
+
[![MIT License](https://img.shields.io/github/license/mashape/apistatus.svg)](LICENSE)
|
8
6
|
|
9
|
-
|
7
|
+
Create ascii art quine from image file.
|
10
8
|
|
11
|
-
|
9
|
+
![Demo.gif](https://github.com/yskoht/aaq/raw/gif/demo.gif)
|
12
10
|
|
13
|
-
|
14
|
-
gem 'aaq'
|
15
|
-
```
|
11
|
+
## Quick start with Docker
|
16
12
|
|
17
|
-
|
13
|
+
You can try aaq easily with [yskoht/aaq](https://hub.docker.com/repository/docker/yskoht/aaq).
|
18
14
|
|
19
15
|
```sh
|
20
|
-
|
16
|
+
# Download sample image
|
17
|
+
curl -O https://github-media-downloads.s3.amazonaws.com/Octocats.zip && unzip Octocats.zip
|
18
|
+
|
19
|
+
# Mount current directory to read image file
|
20
|
+
docker run --rm -v $(pwd):/root yskoht/aaq aaq Octocat/Octocat.png --color
|
21
21
|
```
|
22
22
|
|
23
|
-
|
23
|
+
## Installation
|
24
24
|
|
25
25
|
```sh
|
26
26
|
$ gem install aaq
|
@@ -31,7 +31,7 @@ $ gem install aaq
|
|
31
31
|
Simple quine.
|
32
32
|
|
33
33
|
```sh
|
34
|
-
aaq Octocat/Octocat.png
|
34
|
+
aaq Octocat/Octocat.png
|
35
35
|
```
|
36
36
|
|
37
37
|
Colorful quine.
|
@@ -52,7 +52,7 @@ Put `--color` option.
|
|
52
52
|
aaq Octocat/Octocat.png | xargs -0 -J % ruby -e % '' --color
|
53
53
|
```
|
54
54
|
|
55
|
-
In source code.
|
55
|
+
In your source code.
|
56
56
|
|
57
57
|
```ruby
|
58
58
|
require 'aaq'
|
data/aaq.gemspec
CHANGED
@@ -22,8 +22,8 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
23
|
spec.require_paths = ["lib"]
|
24
24
|
|
25
|
-
spec.add_development_dependency "bundler", "~>
|
26
|
-
spec.add_development_dependency "rake", "~>
|
25
|
+
spec.add_development_dependency "bundler", "~> 2.2.33"
|
26
|
+
spec.add_development_dependency "rake", "~> 12.3.3"
|
27
27
|
spec.add_development_dependency "rspec", "~> 3.0"
|
28
28
|
spec.add_development_dependency "rubocop", "~> 0.58"
|
29
29
|
|
data/exe/aaq
CHANGED
@@ -6,9 +6,33 @@ require 'optparse'
|
|
6
6
|
|
7
7
|
Version = AAQ::VERSION
|
8
8
|
|
9
|
-
|
10
|
-
opt
|
11
|
-
|
9
|
+
options = {}
|
10
|
+
opt = OptionParser.new do |o|
|
11
|
+
o.banner = 'Usage: bundle exec aaq [image] [--color]'
|
12
|
+
o.on('--color', 'Output color ascii-art')
|
13
|
+
o.on('--horizontal N', Integer, 'Number of horizontal pixels per character (default: 6)') do |n|
|
14
|
+
options[:horizontal] = n
|
15
|
+
end
|
16
|
+
o.on('--vertical N', Integer, 'Number of vertical pixels per character (default: 16)') do |n|
|
17
|
+
options[:vertical] = n
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
12
21
|
args = opt.parse(ARGV)
|
22
|
+
if args.empty?
|
23
|
+
puts opt.help
|
24
|
+
exit
|
25
|
+
end
|
13
26
|
|
14
|
-
|
27
|
+
begin
|
28
|
+
eval AAQ::AAQ.new(
|
29
|
+
args.first,
|
30
|
+
options: {
|
31
|
+
unit_horizontal: options[:horizontal],
|
32
|
+
unit_vertical: options[:vertical]
|
33
|
+
}
|
34
|
+
).convert.to_s
|
35
|
+
rescue SyntaxError
|
36
|
+
warn 'Error: The output ascii art is too small to generate the complete code.'
|
37
|
+
warn 'A smaller value for the --horizontal or --vertical options might remove the error.'
|
38
|
+
end
|
data/lib/aaq/version.rb
CHANGED
data/lib/aaq.rb
CHANGED
@@ -5,14 +5,16 @@ require 'set'
|
|
5
5
|
require 'rmagick'
|
6
6
|
|
7
7
|
module AAQ
|
8
|
-
|
9
|
-
|
8
|
+
UNIT_HORIZONTAL_DEFAULT = 6
|
9
|
+
UNIT_VERTICAL_DEFAULT = 14
|
10
10
|
|
11
11
|
class AAQ
|
12
|
-
attr_reader :img, :width, :height, :data, :code
|
12
|
+
attr_reader :img, :width, :height, :data, :code, :unit_horizontal, :unit_vertical
|
13
13
|
|
14
|
-
def initialize(input_img)
|
14
|
+
def initialize(input_img, options: {})
|
15
15
|
org_img = Magick::ImageList.new(input_img)
|
16
|
+
@unit_horizontal = options[:unit_horizontal] || UNIT_HORIZONTAL_DEFAULT
|
17
|
+
@unit_vertical = options[:unit_vertical] || UNIT_VERTICAL_DEFAULT
|
16
18
|
@img, @width, @height = resize(org_img)
|
17
19
|
end
|
18
20
|
|
@@ -73,6 +75,7 @@ module AAQ
|
|
73
75
|
width.times do |w|
|
74
76
|
i = h * width + w
|
75
77
|
next if i < 10
|
78
|
+
|
76
79
|
c += co if i >= c.size
|
77
80
|
str += b.map { |x| x[i] }.include?(1) ? c[k += 1] : ' '
|
78
81
|
end
|
@@ -85,18 +88,18 @@ module AAQ
|
|
85
88
|
private
|
86
89
|
|
87
90
|
def resize(org_img)
|
88
|
-
w = org_img.columns /
|
89
|
-
h = org_img.rows /
|
90
|
-
[org_img.resize(w *
|
91
|
+
w = org_img.columns / @unit_horizontal
|
92
|
+
h = org_img.rows / @unit_vertical
|
93
|
+
[org_img.resize(w * @unit_horizontal, h * @unit_vertical), w, h]
|
91
94
|
end
|
92
95
|
|
93
96
|
def quantize
|
94
97
|
memo = {}
|
95
98
|
|
96
99
|
Array.new(height) do |h|
|
97
|
-
y = h *
|
100
|
+
y = h * @unit_vertical
|
98
101
|
Array.new(width) do |w|
|
99
|
-
x = w *
|
102
|
+
x = w * @unit_horizontal
|
100
103
|
to_256color(mode(x, y), memo)
|
101
104
|
end
|
102
105
|
end
|
@@ -104,8 +107,8 @@ module AAQ
|
|
104
107
|
|
105
108
|
def mode(x, y)
|
106
109
|
h = Hash.new(0)
|
107
|
-
y.upto(y +
|
108
|
-
x.upto(x +
|
110
|
+
y.upto(y + @unit_vertical) do |dy|
|
111
|
+
x.upto(x + @unit_horizontal) do |dx|
|
109
112
|
h[img.pixel_color(dx, dy)] += 1
|
110
113
|
end
|
111
114
|
end
|
@@ -113,7 +116,7 @@ module AAQ
|
|
113
116
|
end
|
114
117
|
|
115
118
|
def to_256(pix)
|
116
|
-
[pix.red /
|
119
|
+
[pix.red / 256, pix.green / 256, pix.blue / 256]
|
117
120
|
end
|
118
121
|
|
119
122
|
def to_256color(pix, memo)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aaq
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- yskoht
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-12-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,28 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 2.2.33
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 2.2.33
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 12.3.3
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 12.3.3
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,7 +80,7 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '2.16'
|
83
|
-
description:
|
83
|
+
description:
|
84
84
|
email:
|
85
85
|
- ysk.oht@gmail.com
|
86
86
|
executables:
|
@@ -93,6 +93,7 @@ files:
|
|
93
93
|
- ".rubocop.yml"
|
94
94
|
- ".rubocop_todo.yml"
|
95
95
|
- ".travis.yml"
|
96
|
+
- Dockerfile
|
96
97
|
- Gemfile
|
97
98
|
- LICENSE.txt
|
98
99
|
- README.md
|
@@ -108,7 +109,7 @@ homepage: https://github.com/yskoht/aaq
|
|
108
109
|
licenses:
|
109
110
|
- MIT
|
110
111
|
metadata: {}
|
111
|
-
post_install_message:
|
112
|
+
post_install_message:
|
112
113
|
rdoc_options: []
|
113
114
|
require_paths:
|
114
115
|
- lib
|
@@ -123,9 +124,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
124
|
- !ruby/object:Gem::Version
|
124
125
|
version: '0'
|
125
126
|
requirements: []
|
126
|
-
|
127
|
-
|
128
|
-
signing_key:
|
127
|
+
rubygems_version: 3.0.3
|
128
|
+
signing_key:
|
129
129
|
specification_version: 4
|
130
130
|
summary: Create ascii art quine from image file
|
131
131
|
test_files: []
|