monsterid 0.1.0
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/.document +5 -0
- data/Gemfile +18 -0
- data/Gemfile.lock +101 -0
- data/LICENSE +23 -0
- data/README.md +11 -0
- data/Rakefile +51 -0
- data/VERSION +1 -0
- data/lib/monsterid.rb +165 -0
- data/lib/parts/arms_1.png +0 -0
- data/lib/parts/arms_2.png +0 -0
- data/lib/parts/arms_3.png +0 -0
- data/lib/parts/arms_4.png +0 -0
- data/lib/parts/arms_5.png +0 -0
- data/lib/parts/arms_S1.png +0 -0
- data/lib/parts/arms_S2.png +0 -0
- data/lib/parts/arms_S3.png +0 -0
- data/lib/parts/arms_S4.png +0 -0
- data/lib/parts/arms_S5.png +0 -0
- data/lib/parts/arms_S6.png +0 -0
- data/lib/parts/arms_S7.png +0 -0
- data/lib/parts/arms_S8.png +0 -0
- data/lib/parts/arms_S9.png +0 -0
- data/lib/parts/back.png +0 -0
- data/lib/parts/body_1.png +0 -0
- data/lib/parts/body_10.png +0 -0
- data/lib/parts/body_11.png +0 -0
- data/lib/parts/body_12.png +0 -0
- data/lib/parts/body_13.png +0 -0
- data/lib/parts/body_14.png +0 -0
- data/lib/parts/body_15.png +0 -0
- data/lib/parts/body_2.png +0 -0
- data/lib/parts/body_3.png +0 -0
- data/lib/parts/body_4.png +0 -0
- data/lib/parts/body_5.png +0 -0
- data/lib/parts/body_6.png +0 -0
- data/lib/parts/body_7.png +0 -0
- data/lib/parts/body_8.png +0 -0
- data/lib/parts/body_9.png +0 -0
- data/lib/parts/body_S1.png +0 -0
- data/lib/parts/body_S2.png +0 -0
- data/lib/parts/body_S3.png +0 -0
- data/lib/parts/body_S4.png +0 -0
- data/lib/parts/body_S5.png +0 -0
- data/lib/parts/eyes_1.png +0 -0
- data/lib/parts/eyes_10.png +0 -0
- data/lib/parts/eyes_11.png +0 -0
- data/lib/parts/eyes_12.png +0 -0
- data/lib/parts/eyes_13.png +0 -0
- data/lib/parts/eyes_14.png +0 -0
- data/lib/parts/eyes_15.png +0 -0
- data/lib/parts/eyes_2.png +0 -0
- data/lib/parts/eyes_3.png +0 -0
- data/lib/parts/eyes_4.png +0 -0
- data/lib/parts/eyes_5.png +0 -0
- data/lib/parts/eyes_6.png +0 -0
- data/lib/parts/eyes_7.png +0 -0
- data/lib/parts/eyes_8.png +0 -0
- data/lib/parts/eyes_9.png +0 -0
- data/lib/parts/eyes_S1.png +0 -0
- data/lib/parts/eyes_S2.png +0 -0
- data/lib/parts/eyes_S3.png +0 -0
- data/lib/parts/eyes_S4.png +0 -0
- data/lib/parts/eyes_S5.png +0 -0
- data/lib/parts/hair_1.png +0 -0
- data/lib/parts/hair_2.png +0 -0
- data/lib/parts/hair_3.png +0 -0
- data/lib/parts/hair_4.png +0 -0
- data/lib/parts/hair_5.png +0 -0
- data/lib/parts/hair_S1.png +0 -0
- data/lib/parts/hair_S2.png +0 -0
- data/lib/parts/hair_S3.png +0 -0
- data/lib/parts/hair_S4.png +0 -0
- data/lib/parts/hair_S5.png +0 -0
- data/lib/parts/hair_S6.png +0 -0
- data/lib/parts/hair_S7.png +0 -0
- data/lib/parts/image.info +103 -0
- data/lib/parts/legs_1.png +0 -0
- data/lib/parts/legs_2.png +0 -0
- data/lib/parts/legs_3.png +0 -0
- data/lib/parts/legs_4.png +0 -0
- data/lib/parts/legs_5.png +0 -0
- data/lib/parts/legs_S1.png +0 -0
- data/lib/parts/legs_S10.png +0 -0
- data/lib/parts/legs_S11.png +0 -0
- data/lib/parts/legs_S12.png +0 -0
- data/lib/parts/legs_S13.png +0 -0
- data/lib/parts/legs_S2.png +0 -0
- data/lib/parts/legs_S3.png +0 -0
- data/lib/parts/legs_S4.png +0 -0
- data/lib/parts/legs_S5.png +0 -0
- data/lib/parts/legs_S6.png +0 -0
- data/lib/parts/legs_S7.png +0 -0
- data/lib/parts/legs_S8.png +0 -0
- data/lib/parts/legs_S9.png +0 -0
- data/lib/parts/monsterparts.xcf +0 -0
- data/lib/parts/mouth_1.png +0 -0
- data/lib/parts/mouth_10.png +0 -0
- data/lib/parts/mouth_2.png +0 -0
- data/lib/parts/mouth_3.png +0 -0
- data/lib/parts/mouth_4.png +0 -0
- data/lib/parts/mouth_5.png +0 -0
- data/lib/parts/mouth_6.png +0 -0
- data/lib/parts/mouth_7.png +0 -0
- data/lib/parts/mouth_8.png +0 -0
- data/lib/parts/mouth_9.png +0 -0
- data/lib/parts/mouth_S1.png +0 -0
- data/lib/parts/mouth_S2.png +0 -0
- data/lib/parts/mouth_S3.png +0 -0
- data/lib/parts/mouth_S4.png +0 -0
- data/lib/parts/mouth_S5.png +0 -0
- data/lib/parts/mouth_S6.png +0 -0
- data/lib/parts/mouth_S7.png +0 -0
- data/monsterid.gemspec +175 -0
- data/test/helper.rb +34 -0
- metadata +272 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 2179f7a408502e0c774911440899db23bcc5cdc3
|
|
4
|
+
data.tar.gz: 0b5f701dc34f1f061475ff0b9b842890d37819a7
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: de6fde257202edf5fdce322c4279f548cee79499f7fa0539fc0d204ecd846415af37be60f16861446ea59c168c468fdbd35fd2cfe5d09e923ad1031ecb7e88af
|
|
7
|
+
data.tar.gz: 4310a9d8c4e11c58a6ecdbc6441b1c52b947cafa54abe31342185d46ec121f94f2a0d227736135bf7ff56807b9ba720894e8ca0eb3b4530c8665073b3dc5a4b0
|
data/.document
ADDED
data/Gemfile
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
source "http://rubygems.org"
|
|
2
|
+
# Add dependencies required to use your gem here.
|
|
3
|
+
# Example:
|
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
|
5
|
+
gem "oily_png", "~> 1.1"
|
|
6
|
+
gem "color", "~> 1.7"
|
|
7
|
+
|
|
8
|
+
# Add dependencies to develop your gem here.
|
|
9
|
+
# Include everything needed to run rake, tests, features, etc.
|
|
10
|
+
group :development do
|
|
11
|
+
gem "shoulda", ">= 0"
|
|
12
|
+
gem "rdoc", "~> 3.12"
|
|
13
|
+
gem "bundler", "~> 1.0"
|
|
14
|
+
gem "jeweler", "~> 2.0.1"
|
|
15
|
+
gem "simplecov", ">= 0"
|
|
16
|
+
gem "rubocop"
|
|
17
|
+
end
|
|
18
|
+
|
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
GEM
|
|
2
|
+
remote: http://rubygems.org/
|
|
3
|
+
specs:
|
|
4
|
+
activesupport (4.1.1)
|
|
5
|
+
i18n (~> 0.6, >= 0.6.9)
|
|
6
|
+
json (~> 1.7, >= 1.7.7)
|
|
7
|
+
minitest (~> 5.1)
|
|
8
|
+
thread_safe (~> 0.1)
|
|
9
|
+
tzinfo (~> 1.1)
|
|
10
|
+
addressable (2.3.6)
|
|
11
|
+
ast (2.0.0)
|
|
12
|
+
builder (3.2.2)
|
|
13
|
+
chunky_png (1.3.1)
|
|
14
|
+
color (1.7)
|
|
15
|
+
descendants_tracker (0.0.4)
|
|
16
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
|
17
|
+
docile (1.1.5)
|
|
18
|
+
faraday (0.9.0)
|
|
19
|
+
multipart-post (>= 1.2, < 3)
|
|
20
|
+
git (1.2.7)
|
|
21
|
+
github_api (0.11.3)
|
|
22
|
+
addressable (~> 2.3)
|
|
23
|
+
descendants_tracker (~> 0.0.1)
|
|
24
|
+
faraday (~> 0.8, < 0.10)
|
|
25
|
+
hashie (>= 1.2)
|
|
26
|
+
multi_json (>= 1.7.5, < 2.0)
|
|
27
|
+
nokogiri (~> 1.6.0)
|
|
28
|
+
oauth2
|
|
29
|
+
hashie (3.0.0)
|
|
30
|
+
highline (1.6.21)
|
|
31
|
+
i18n (0.6.9)
|
|
32
|
+
jeweler (2.0.1)
|
|
33
|
+
builder
|
|
34
|
+
bundler (>= 1.0)
|
|
35
|
+
git (>= 1.2.5)
|
|
36
|
+
github_api
|
|
37
|
+
highline (>= 1.6.15)
|
|
38
|
+
nokogiri (>= 1.5.10)
|
|
39
|
+
rake
|
|
40
|
+
rdoc
|
|
41
|
+
json (1.8.1)
|
|
42
|
+
jwt (1.0.0)
|
|
43
|
+
mini_portile (0.6.0)
|
|
44
|
+
minitest (5.3.5)
|
|
45
|
+
multi_json (1.10.1)
|
|
46
|
+
multi_xml (0.5.5)
|
|
47
|
+
multipart-post (2.0.0)
|
|
48
|
+
nokogiri (1.6.2.1)
|
|
49
|
+
mini_portile (= 0.6.0)
|
|
50
|
+
oauth2 (0.9.4)
|
|
51
|
+
faraday (>= 0.8, < 0.10)
|
|
52
|
+
jwt (~> 1.0)
|
|
53
|
+
multi_json (~> 1.3)
|
|
54
|
+
multi_xml (~> 0.5)
|
|
55
|
+
rack (~> 1.2)
|
|
56
|
+
oily_png (1.1.1)
|
|
57
|
+
chunky_png (~> 1.3.0)
|
|
58
|
+
parser (2.1.9)
|
|
59
|
+
ast (>= 1.1, < 3.0)
|
|
60
|
+
slop (~> 3.4, >= 3.4.5)
|
|
61
|
+
powerpack (0.0.9)
|
|
62
|
+
rack (1.5.2)
|
|
63
|
+
rainbow (2.0.0)
|
|
64
|
+
rake (10.3.2)
|
|
65
|
+
rdoc (3.12.2)
|
|
66
|
+
json (~> 1.4)
|
|
67
|
+
rubocop (0.23.0)
|
|
68
|
+
json (>= 1.7.7, < 2)
|
|
69
|
+
parser (~> 2.1.9)
|
|
70
|
+
powerpack (~> 0.0.6)
|
|
71
|
+
rainbow (>= 1.99.1, < 3.0)
|
|
72
|
+
ruby-progressbar (~> 1.4)
|
|
73
|
+
ruby-progressbar (1.5.1)
|
|
74
|
+
shoulda (3.5.0)
|
|
75
|
+
shoulda-context (~> 1.0, >= 1.0.1)
|
|
76
|
+
shoulda-matchers (>= 1.4.1, < 3.0)
|
|
77
|
+
shoulda-context (1.2.1)
|
|
78
|
+
shoulda-matchers (2.6.1)
|
|
79
|
+
activesupport (>= 3.0.0)
|
|
80
|
+
simplecov (0.8.2)
|
|
81
|
+
docile (~> 1.1.0)
|
|
82
|
+
multi_json
|
|
83
|
+
simplecov-html (~> 0.8.0)
|
|
84
|
+
simplecov-html (0.8.0)
|
|
85
|
+
slop (3.5.0)
|
|
86
|
+
thread_safe (0.3.4)
|
|
87
|
+
tzinfo (1.2.1)
|
|
88
|
+
thread_safe (~> 0.1)
|
|
89
|
+
|
|
90
|
+
PLATFORMS
|
|
91
|
+
ruby
|
|
92
|
+
|
|
93
|
+
DEPENDENCIES
|
|
94
|
+
bundler (~> 1.0)
|
|
95
|
+
color (~> 1.7)
|
|
96
|
+
jeweler (~> 2.0.1)
|
|
97
|
+
oily_png (~> 1.1)
|
|
98
|
+
rdoc (~> 3.12)
|
|
99
|
+
rubocop
|
|
100
|
+
shoulda
|
|
101
|
+
simplecov
|
data/LICENSE
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
Copyright (c) 2014 Knut Aldrin Wikström
|
|
2
|
+
|
|
3
|
+
Original php project by Andreas Gohr (http://www.splitbrain.org/projects/monsterid)
|
|
4
|
+
Monster icons by Katherine Garner (http://kathgarner.com/)
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
7
|
+
a copy of this software and associated documentation files (the
|
|
8
|
+
"Software"), to deal in the Software without restriction, including
|
|
9
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
10
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
11
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
12
|
+
the following conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be
|
|
15
|
+
included in all copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
18
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
19
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
20
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
21
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
22
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
23
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
MonsterID
|
|
2
|
+
================
|
|
3
|
+
|
|
4
|
+
A port of the php script by Andreas Gohr (http://www.splitbrain.org/projects/monsterid).
|
|
5
|
+
Actually kinda more like a rewrite.
|
|
6
|
+
|
|
7
|
+
Feel free to use/steal/share/improve.
|
|
8
|
+
|
|
9
|
+
Copyright (c) 2014 Knut Aldrin Wikström. See LICENSE for
|
|
10
|
+
further details.
|
|
11
|
+
|
data/Rakefile
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'rubygems'
|
|
4
|
+
require 'bundler'
|
|
5
|
+
begin
|
|
6
|
+
Bundler.setup(:default, :development)
|
|
7
|
+
rescue Bundler::BundlerError => e
|
|
8
|
+
$stderr.puts e.message
|
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
|
10
|
+
exit e.status_code
|
|
11
|
+
end
|
|
12
|
+
require 'rake'
|
|
13
|
+
|
|
14
|
+
require 'jeweler'
|
|
15
|
+
Jeweler::Tasks.new do |gem|
|
|
16
|
+
# gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
|
|
17
|
+
gem.name = "monsterid"
|
|
18
|
+
gem.homepage = "http://github.com/knutaldrin/monsterid"
|
|
19
|
+
gem.license = "CC BY 4.0"
|
|
20
|
+
gem.summary = %Q{Generates tiny little monsters to discern users.}
|
|
21
|
+
gem.description = %Q{Port/rework of the php script, with new monsters snatched from the WP plugin}
|
|
22
|
+
gem.email = "knutaldrin@gmail.com"
|
|
23
|
+
gem.authors = ["Knut Aldrin Wikström"]
|
|
24
|
+
# dependencies defined in Gemfile
|
|
25
|
+
end
|
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
|
27
|
+
|
|
28
|
+
require 'rake/testtask'
|
|
29
|
+
Rake::TestTask.new(:test) do |test|
|
|
30
|
+
test.libs << 'lib' << 'test'
|
|
31
|
+
test.pattern = 'test/**/test_*.rb'
|
|
32
|
+
test.verbose = true
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
desc "Code coverage detail"
|
|
36
|
+
task :simplecov do
|
|
37
|
+
ENV['COVERAGE'] = "true"
|
|
38
|
+
Rake::Task['test'].execute
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
task :default => :test
|
|
42
|
+
|
|
43
|
+
require 'rdoc/task'
|
|
44
|
+
Rake::RDocTask.new do |rdoc|
|
|
45
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
|
46
|
+
|
|
47
|
+
rdoc.rdoc_dir = 'rdoc'
|
|
48
|
+
rdoc.title = "monsterid #{version}"
|
|
49
|
+
rdoc.rdoc_files.include('README*')
|
|
50
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
51
|
+
end
|
data/VERSION
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0.1.0
|
data/lib/monsterid.rb
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
require 'oily_png'
|
|
2
|
+
require 'digest'
|
|
3
|
+
require 'color'
|
|
4
|
+
require 'base64'
|
|
5
|
+
|
|
6
|
+
# Generates cute monsters from a seed
|
|
7
|
+
class MonsterID
|
|
8
|
+
WHITE_PARTS = [
|
|
9
|
+
'arms_1.png', 'arms_2.png', 'arms_S4.png', 'eye_13.png',
|
|
10
|
+
'hair_1.png', 'hair_2.png', 'hair_3.png', 'hair_5.png',
|
|
11
|
+
'legs_4.png', 'legs_S8.png', 'legs_S11.png', 'mouth_5.png',
|
|
12
|
+
'mouth_8.png', 'mouth_S1.png', 'mouth_S3.png', 'mouth_2.png',
|
|
13
|
+
'eyes_13.png', 'legs_S13.png', 'mouth_S7.png'
|
|
14
|
+
]
|
|
15
|
+
BODY_COLOR_PARTS = [
|
|
16
|
+
'arms_S8.png', 'legs_S5.png',
|
|
17
|
+
'mouth_S5.png', 'mouth_S4.png'
|
|
18
|
+
]
|
|
19
|
+
SPECIFIC_COLOR_PARTS = {
|
|
20
|
+
'arms_S2.png' => [0, 200],
|
|
21
|
+
'hair_S6.png' => [0, 200],
|
|
22
|
+
'mouth_9.png' => [0, 200],
|
|
23
|
+
'mouth_6.png' => [0, 200],
|
|
24
|
+
'mouth_S2.png' => [0, 200]
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
PARTS = {
|
|
28
|
+
:arms => [
|
|
29
|
+
'arms_1.png', 'arms_2.png', 'arms_3.png', 'arms_4.png', 'arms_5.png',
|
|
30
|
+
'arms_S1.png', 'arms_S2.png', 'arms_S3.png', 'arms_S4.png', 'arms_S5.png',
|
|
31
|
+
'arms_S6.png', 'arms_S7.png', 'arms_S8.png', 'arms_S9.png'
|
|
32
|
+
],
|
|
33
|
+
:body => [
|
|
34
|
+
'body_1.png', 'body_2.png', 'body_3.png', 'body_4.png', 'body_5.png',
|
|
35
|
+
'body_6.png', 'body_7.png', 'body_8.png', 'body_9.png', 'body_10.png',
|
|
36
|
+
'body_11.png', 'body_12.png', 'body_13.png', 'body_14.png', 'body_15.png',
|
|
37
|
+
'body_S1.png', 'body_S2.png', 'body_S3.png', 'body_S4.png', 'body_S5.png'
|
|
38
|
+
],
|
|
39
|
+
:eyes => [
|
|
40
|
+
'eyes_1.png', 'eyes_2.png', 'eyes_3.png', 'eyes_4.png', 'eyes_5.png',
|
|
41
|
+
'eyes_6.png', 'eyes_7.png', 'eyes_8.png', 'eyes_9.png', 'eyes_10.png',
|
|
42
|
+
'eyes_11.png', 'eyes_12.png', 'eyes_13.png', 'eyes_14.png', 'eyes_15.png',
|
|
43
|
+
'eyes_S1.png', 'eyes_S2.png', 'eyes_S3.png', 'eyes_S4.png', 'eyes_S5.png'
|
|
44
|
+
],
|
|
45
|
+
:hair => [
|
|
46
|
+
'hair_1.png', 'hair_2.png', 'hair_3.png', 'hair_4.png', 'hair_5.png',
|
|
47
|
+
'hair_S1.png', 'hair_S2.png', 'hair_S3.png', 'hair_S4.png', 'hair_S5.png',
|
|
48
|
+
'hair_S6.png', 'hair_S7.png'
|
|
49
|
+
],
|
|
50
|
+
:legs => [
|
|
51
|
+
'legs_1.png', 'legs_2.png', 'legs_3.png', 'legs_4.png', 'legs_5.png',
|
|
52
|
+
'legs_S1.png', 'legs_S10.png', 'legs_S11.png', 'legs_S12.png',
|
|
53
|
+
'legs_S13.png', 'legs_S2.png', 'legs_S3.png', 'legs_S4.png',
|
|
54
|
+
'legs_S5.png', 'legs_S6.png', 'legs_S7.png', 'legs_S8.png', 'legs_S9.png'
|
|
55
|
+
],
|
|
56
|
+
:mouth => [
|
|
57
|
+
'mouth_1.png', 'mouth_2.png', 'mouth_3.png', 'mouth_4.png', 'mouth_5.png',
|
|
58
|
+
'mouth_6.png', 'mouth_7.png', 'mouth_8.png', 'mouth_9.png', 'mouth_10.png',
|
|
59
|
+
'mouth_S1.png', 'mouth_S2.png', 'mouth_S3.png', 'mouth_S4.png', 'mouth_S5.png',
|
|
60
|
+
'mouth_S6.png', 'mouth_S7.png'
|
|
61
|
+
]
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
# Remove body 12 for now, doesn't look good
|
|
65
|
+
PARTS[:body].delete( 'body_12.png' )
|
|
66
|
+
|
|
67
|
+
# Test color set [hue, sat]
|
|
68
|
+
COLORS = [
|
|
69
|
+
[8, 255], [160, 64], [8, 127], [184, 255],
|
|
70
|
+
[24, 191], [208, 191], [40, 255], [208, 64],
|
|
71
|
+
[48, 64], [248, 191], [72, 127], [272, 64],
|
|
72
|
+
[128, 255], [312, 191], [160, 255], [336, 255]
|
|
73
|
+
]
|
|
74
|
+
|
|
75
|
+
def initialize(seed, size = 120)
|
|
76
|
+
@id = Digest::SHA1.hexdigest seed.to_s
|
|
77
|
+
|
|
78
|
+
parts = {
|
|
79
|
+
:legs => {
|
|
80
|
+
:part => PARTS[:legs ][@id[0, 2].hex % PARTS[:legs ].length],
|
|
81
|
+
:color => COLORS[@id[2, 2].hex % COLORS.length]
|
|
82
|
+
},
|
|
83
|
+
:hair => {
|
|
84
|
+
:part => PARTS[:hair ][@id[4, 2].hex % PARTS[:hair ].length],
|
|
85
|
+
:color => COLORS[@id[6, 2].hex % COLORS.length]
|
|
86
|
+
},
|
|
87
|
+
:arms => {
|
|
88
|
+
:part => PARTS[:arms ][@id[8, 2].hex % PARTS[:arms ].length],
|
|
89
|
+
:color => COLORS[@id[10, 2].hex % COLORS.length]
|
|
90
|
+
},
|
|
91
|
+
:body => {
|
|
92
|
+
:part => PARTS[:body ][@id[12, 2].hex % PARTS[:body ].length],
|
|
93
|
+
:color => COLORS[@id[14, 2].hex % COLORS.length]
|
|
94
|
+
},
|
|
95
|
+
:eyes => {
|
|
96
|
+
:part => PARTS[:eyes ][@id[16, 2].hex % PARTS[:eyes ].length],
|
|
97
|
+
:color => COLORS[@id[18, 2].hex % COLORS.length]
|
|
98
|
+
},
|
|
99
|
+
:mouth => {
|
|
100
|
+
:part => PARTS[:mouth][@id[20, 2].hex % PARTS[:mouth].length],
|
|
101
|
+
:color => COLORS[@id[22, 2].hex % COLORS.length]
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
@monster = ChunkyPNG::Image.new(120, 120, ChunkyPNG::Color::TRANSPARENT)
|
|
106
|
+
|
|
107
|
+
parts.each do |_, part|
|
|
108
|
+
path = File.join(File.dirname(__FILE__), 'parts', part[:part])
|
|
109
|
+
partimg = ChunkyPNG::Image.from_file(path)
|
|
110
|
+
|
|
111
|
+
if BODY_COLOR_PARTS.include? part[:part]
|
|
112
|
+
part[:color] = parts[:body][:color]
|
|
113
|
+
elsif SPECIFIC_COLOR_PARTS.include? part[:part]
|
|
114
|
+
part[:color] = SPECIFIC_COLOR_PARTS[part[:part]]
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
unless WHITE_PARTS.include? part[:part]
|
|
118
|
+
partimg = colorise(partimg, part[:color][0], part[:color][1])
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
@monster.compose!(partimg)
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
resize(size) unless size == 120
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def resize(size)
|
|
128
|
+
@monster.resample_bilinear!(size, size)
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def save(path)
|
|
132
|
+
@monster.save path
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
def to_datastream
|
|
136
|
+
@monster.to_datastream
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
def to_data_uri
|
|
140
|
+
'data:image/png;base64,' +
|
|
141
|
+
Base64.strict_encode64(@monster.to_datastream.to_s)
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
def inspect
|
|
145
|
+
"#<#{self.class.name}:#{object_id} id: #{@id}>"
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
private
|
|
149
|
+
|
|
150
|
+
def colorise(img, hue, sat = 255)
|
|
151
|
+
img.pixels.map! do |px|
|
|
152
|
+
pxrgb = Color::RGB.new(ChunkyPNG::Color.r(px),
|
|
153
|
+
ChunkyPNG::Color.g(px),
|
|
154
|
+
ChunkyPNG::Color.b(px))
|
|
155
|
+
pxhsl = pxrgb.to_hsl
|
|
156
|
+
pxhsl.saturation = sat
|
|
157
|
+
pxhsl.hue = hue
|
|
158
|
+
newrgb = pxhsl.to_rgb
|
|
159
|
+
|
|
160
|
+
ChunkyPNG::Color.rgba(newrgb.red.to_i, newrgb.green.to_i, newrgb.blue.to_i, ChunkyPNG::Color.a(px))
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
img
|
|
164
|
+
end
|
|
165
|
+
end
|
|
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
|
data/lib/parts/back.png
ADDED
|
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
|
|
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
|