boring_avatar 0.1.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.semaphore/semaphore.yml +1 -1
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +4 -2
- data/README.md +9 -5
- data/boring_avatar.gemspec +1 -1
- data/color_palettes.json +1 -0
- data/lib/boring_avatar/avatar/base.rb +9 -5
- data/lib/boring_avatar/avatar/bauhaus.rb +16 -20
- data/lib/boring_avatar/avatar/beam.rb +38 -42
- data/lib/boring_avatar/avatar/marble.rb +16 -20
- data/lib/boring_avatar/avatar/ring.rb +45 -0
- data/lib/boring_avatar/avatar/sunset.rb +22 -26
- data/lib/boring_avatar/util.rb +12 -0
- data/lib/boring_avatar/version.rb +1 -1
- data/lib/boring_avatar.rb +1 -0
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e6772d0356af50712128cf66783ccd72b45a7af8689adb2384d2e95250f63bdb
|
4
|
+
data.tar.gz: d42b37d5ef921d8bb7699610a5c50a24d712f977b207605e20453b280d563329
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 98bc31baeb25c0eb26d3c675280fe4247084c8048a821ea020094a3fd9eec891b0cfdee0d52d28eb692db4acecf9f9c6ebc54961c5ced812f17fdf6450ab6989
|
7
|
+
data.tar.gz: c50ec05e86712de188842e721dbe7e3052a178a43f4bd2a0989a7debb640b5599d0a5bdb8b8a345a5ba0413ec4e4ce15ecc451220be5e6fc56558c924fc7e55d
|
data/.semaphore/semaphore.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
boring_avatar (0.
|
4
|
+
boring_avatar (1.0.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -10,6 +10,8 @@ GEM
|
|
10
10
|
rake (12.3.3)
|
11
11
|
|
12
12
|
PLATFORMS
|
13
|
+
arm64-darwin-21
|
14
|
+
x86_64-darwin-19
|
13
15
|
x86_64-darwin-20
|
14
16
|
x86_64-linux
|
15
17
|
|
@@ -19,4 +21,4 @@ DEPENDENCIES
|
|
19
21
|
rake (~> 12.0)
|
20
22
|
|
21
23
|
BUNDLED WITH
|
22
|
-
2.
|
24
|
+
2.3.20
|
data/README.md
CHANGED
@@ -8,6 +8,7 @@ Currently only supporting the following variants:
|
|
8
8
|
- Bauhaus
|
9
9
|
- Beam
|
10
10
|
- Marble
|
11
|
+
- Ring
|
11
12
|
- Sunset
|
12
13
|
|
13
14
|
## Installation
|
@@ -29,10 +30,11 @@ Or install it yourself as:
|
|
29
30
|
## Usage
|
30
31
|
|
31
32
|
```ruby
|
32
|
-
BoringAvatar::Bauhaus.generate
|
33
|
-
BoringAvatar::Beam.
|
34
|
-
BoringAvatar::
|
35
|
-
BoringAvatar::
|
33
|
+
BoringAvatar::Bauhaus.new.generate
|
34
|
+
BoringAvatar::Beam.new(name: "John Doe").generate
|
35
|
+
BoringAvatar::Beam.new(colors: "random").generate
|
36
|
+
BoringAvatar::Marble.new(name: "John Doe", size: 40).generate
|
37
|
+
BoringAvatar::Sunset.new(name: "John Doe", size: 40, colors: %w[#a3a948 #edb92e #f85931 #ce1836 #009989]).generate
|
36
38
|
```
|
37
39
|
|
38
40
|
There is also an [online service](https://github.com/hihayk/boring-avatars-service/) should you wish to build a wrapper around the API.
|
@@ -45,8 +47,10 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
45
47
|
|
46
48
|
## Contributing
|
47
49
|
|
48
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
50
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/olimart/boring_avatar.
|
49
51
|
|
50
52
|
## License
|
51
53
|
|
52
54
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
55
|
+
|
56
|
+
Color palettes from [Nice color palettes](https://github.com/Jam3/nice-color-palettes/)
|
data/boring_avatar.gemspec
CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |spec|
|
|
7
7
|
spec.email = ["olivier@yafoy.com"]
|
8
8
|
|
9
9
|
spec.summary = "Generate Boring Avatars"
|
10
|
-
spec.description = "This is a simple Ruby implementation of Boring Avatars"
|
10
|
+
spec.description = "This is a simple Ruby implementation of Boring Avatars library"
|
11
11
|
spec.homepage = "https://github.com/olimart/boring_avatar"
|
12
12
|
spec.license = "MIT"
|
13
13
|
spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
|
data/color_palettes.json
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
[["#69d2e7","#a7dbd8","#e0e4cc","#f38630","#fa6900"],["#fe4365","#fc9d9a","#f9cdad","#c8c8a9","#83af9b"],["#ecd078","#d95b43","#c02942","#542437","#53777a"],["#556270","#4ecdc4","#c7f464","#ff6b6b","#c44d58"],["#774f38","#e08e79","#f1d4af","#ece5ce","#c5e0dc"],["#e8ddcb","#cdb380","#036564","#033649","#031634"],["#490a3d","#bd1550","#e97f02","#f8ca00","#8a9b0f"],["#594f4f","#547980","#45ada8","#9de0ad","#e5fcc2"],["#00a0b0","#6a4a3c","#cc333f","#eb6841","#edc951"],["#e94e77","#d68189","#c6a49a","#c6e5d9","#f4ead5"],["#3fb8af","#7fc7af","#dad8a7","#ff9e9d","#ff3d7f"],["#d9ceb2","#948c75","#d5ded9","#7a6a53","#99b2b7"],["#ffffff","#cbe86b","#f2e9e1","#1c140d","#cbe86b"],["#efffcd","#dce9be","#555152","#2e2633","#99173c"],["#343838","#005f6b","#008c9e","#00b4cc","#00dffc"],["#413e4a","#73626e","#b38184","#f0b49e","#f7e4be"],["#ff4e50","#fc913a","#f9d423","#ede574","#e1f5c4"],["#99b898","#fecea8","#ff847c","#e84a5f","#2a363b"],["#655643","#80bca3","#f6f7bd","#e6ac27","#bf4d28"],["#00a8c6","#40c0cb","#f9f2e7","#aee239","#8fbe00"],["#351330","#424254","#64908a","#e8caa4","#cc2a41"],["#554236","#f77825","#d3ce3d","#f1efa5","#60b99a"],["#5d4157","#838689","#a8caba","#cad7b2","#ebe3aa"],["#8c2318","#5e8c6a","#88a65e","#bfb35a","#f2c45a"],["#fad089","#ff9c5b","#f5634a","#ed303c","#3b8183"],["#ff4242","#f4fad2","#d4ee5e","#e1edb9","#f0f2eb"],["#f8b195","#f67280","#c06c84","#6c5b7b","#355c7d"],["#d1e751","#ffffff","#000000","#4dbce9","#26ade4"],["#1b676b","#519548","#88c425","#bef202","#eafde6"],["#5e412f","#fcebb6","#78c0a8","#f07818","#f0a830"],["#bcbdac","#cfbe27","#f27435","#f02475","#3b2d38"],["#452632","#91204d","#e4844a","#e8bf56","#e2f7ce"],["#eee6ab","#c5bc8e","#696758","#45484b","#36393b"],["#f0d8a8","#3d1c00","#86b8b1","#f2d694","#fa2a00"],["#2a044a","#0b2e59","#0d6759","#7ab317","#a0c55f"],["#f04155","#ff823a","#f2f26f","#fff7bd","#95cfb7"],["#b9d7d9","#668284","#2a2829","#493736","#7b3b3b"],["#bbbb88","#ccc68d","#eedd99","#eec290","#eeaa88"],["#b3cc57","#ecf081","#ffbe40","#ef746f","#ab3e5b"],["#a3a948","#edb92e","#f85931","#ce1836","#009989"],["#300030","#480048","#601848","#c04848","#f07241"],["#67917a","#170409","#b8af03","#ccbf82","#e33258"],["#aab3ab","#c4cbb7","#ebefc9","#eee0b7","#e8caaf"],["#e8d5b7","#0e2430","#fc3a51","#f5b349","#e8d5b9"],["#ab526b","#bca297","#c5ceae","#f0e2a4","#f4ebc3"],["#607848","#789048","#c0d860","#f0f0d8","#604848"],["#b6d8c0","#c8d9bf","#dadabd","#ecdbbc","#fedcba"],["#a8e6ce","#dcedc2","#ffd3b5","#ffaaa6","#ff8c94"],["#3e4147","#fffedf","#dfba69","#5a2e2e","#2a2c31"],["#fc354c","#29221f","#13747d","#0abfbc","#fcf7c5"],["#cc0c39","#e6781e","#c8cf02","#f8fcc1","#1693a7"],["#1c2130","#028f76","#b3e099","#ffeaad","#d14334"],["#a7c5bd","#e5ddcb","#eb7b59","#cf4647","#524656"],["#dad6ca","#1bb0ce","#4f8699","#6a5e72","#563444"],["#5c323e","#a82743","#e15e32","#c0d23e","#e5f04c"],["#edebe6","#d6e1c7","#94c7b6","#403b33","#d3643b"],["#fdf1cc","#c6d6b8","#987f69","#e3ad40","#fcd036"],["#230f2b","#f21d41","#ebebbc","#bce3c5","#82b3ae"],["#b9d3b0","#81bda4","#b28774","#f88f79","#f6aa93"],["#3a111c","#574951","#83988e","#bcdea5","#e6f9bc"],["#5e3929","#cd8c52","#b7d1a3","#dee8be","#fcf7d3"],["#1c0113","#6b0103","#a30006","#c21a01","#f03c02"],["#000000","#9f111b","#b11623","#292c37","#cccccc"],["#382f32","#ffeaf2","#fcd9e5","#fbc5d8","#f1396d"],["#e3dfba","#c8d6bf","#93ccc6","#6cbdb5","#1a1f1e"],["#f6f6f6","#e8e8e8","#333333","#990100","#b90504"],["#1b325f","#9cc4e4","#e9f2f9","#3a89c9","#f26c4f"],["#a1dbb2","#fee5ad","#faca66","#f7a541","#f45d4c"],["#c1b398","#605951","#fbeec2","#61a6ab","#accec0"],["#5e9fa3","#dcd1b4","#fab87f","#f87e7b","#b05574"],["#951f2b","#f5f4d7","#e0dfb1","#a5a36c","#535233"],["#8dccad","#988864","#fea6a2","#f9d6ac","#ffe9af"],["#2d2d29","#215a6d","#3ca2a2","#92c7a3","#dfece6"],["#413d3d","#040004","#c8ff00","#fa023c","#4b000f"],["#eff3cd","#b2d5ba","#61ada0","#248f8d","#605063"],["#ffefd3","#fffee4","#d0ecea","#9fd6d2","#8b7a5e"],["#cfffdd","#b4dec1","#5c5863","#a85163","#ff1f4c"],["#9dc9ac","#fffec7","#f56218","#ff9d2e","#919167"],["#4e395d","#827085","#8ebe94","#ccfc8e","#dc5b3e"],["#a8a7a7","#cc527a","#e8175d","#474747","#363636"],["#f8edd1","#d88a8a","#474843","#9d9d93","#c5cfc6"],["#046d8b","#309292","#2fb8ac","#93a42a","#ecbe13"],["#f38a8a","#55443d","#a0cab5","#cde9ca","#f1edd0"],["#a70267","#f10c49","#fb6b41","#f6d86b","#339194"],["#ff003c","#ff8a00","#fabe28","#88c100","#00c176"],["#ffedbf","#f7803c","#f54828","#2e0d23","#f8e4c1"],["#4e4d4a","#353432","#94ba65","#2790b0","#2b4e72"],["#0ca5b0","#4e3f30","#fefeeb","#f8f4e4","#a5b3aa"],["#4d3b3b","#de6262","#ffb88c","#ffd0b3","#f5e0d3"],["#fffbb7","#a6f6af","#66b6ab","#5b7c8d","#4f2958"],["#edf6ee","#d1c089","#b3204d","#412e28","#151101"],["#9d7e79","#ccac95","#9a947c","#748b83","#5b756c"],["#fcfef5","#e9ffe1","#cdcfb7","#d6e6c3","#fafbe3"],["#9cddc8","#bfd8ad","#ddd9ab","#f7af63","#633d2e"],["#30261c","#403831","#36544f","#1f5f61","#0b8185"],["#aaff00","#ffaa00","#ff00aa","#aa00ff","#00aaff"],["#d1313d","#e5625c","#f9bf76","#8eb2c5","#615375"],["#ffe181","#eee9e5","#fad3b2","#ffba7f","#ff9c97"],["#73c8a9","#dee1b6","#e1b866","#bd5532","#373b44"],["#805841","#dcf7f3","#fffcdd","#ffd8d8","#f5a2a2"]]
|
@@ -2,14 +2,14 @@
|
|
2
2
|
|
3
3
|
module BoringAvatar
|
4
4
|
class Base
|
5
|
-
COLORS = %w[#92a1c6 #146a7c #f0ab3d #c271b4 #c20d90]
|
6
|
-
NAME = "Clara Barton"
|
7
|
-
SIZE = 40
|
5
|
+
COLORS = %w[#92a1c6 #146a7c #f0ab3d #c271b4 #c20d90].freeze
|
6
|
+
NAME = "Clara Barton".freeze
|
7
|
+
SIZE = 40.freeze
|
8
8
|
|
9
9
|
attr_reader :colors, :name, :size, :opts, :num_from_name, :range
|
10
10
|
|
11
11
|
def initialize(colors: COLORS, name: NAME, size: SIZE, **opts)
|
12
|
-
@colors = colors
|
12
|
+
@colors = colors == "random" ? Util.random_palette : colors
|
13
13
|
@name = name
|
14
14
|
@size = size
|
15
15
|
@opts = opts
|
@@ -18,11 +18,15 @@ module BoringAvatar
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def generate
|
21
|
-
|
21
|
+
render_svg(template)
|
22
22
|
end
|
23
23
|
|
24
24
|
private
|
25
25
|
|
26
|
+
def template
|
27
|
+
raise NotImplementedError
|
28
|
+
end
|
29
|
+
|
26
30
|
def render_svg(text)
|
27
31
|
text
|
28
32
|
.gsub(/>\s+</, "><")
|
@@ -2,29 +2,13 @@
|
|
2
2
|
|
3
3
|
module BoringAvatar
|
4
4
|
class Bauhaus < Base
|
5
|
-
ELEMENTS = 4
|
6
|
-
SIZE = 80
|
7
|
-
|
8
|
-
def generate
|
9
|
-
template(generate_colors)
|
10
|
-
end
|
5
|
+
ELEMENTS = 4.freeze
|
6
|
+
SIZE = 80.freeze
|
11
7
|
|
12
8
|
private
|
13
9
|
|
14
|
-
def
|
15
|
-
|
16
|
-
arr << {
|
17
|
-
color: Util.get_random_color(colors, num_from_name + i, range),
|
18
|
-
translateX: Util.get_unit(num_from_name * (i + 1), (SIZE/2 - (i + 17)), 1),
|
19
|
-
translateY: Util.get_unit(num_from_name * (i + 1), (SIZE/2 - (i + 17)), 2),
|
20
|
-
rotate: Util.get_unit(num_from_name * (i + 1), 360),
|
21
|
-
isSquare: Util.get_boolean(num_from_name, 2)
|
22
|
-
}
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def template(properties)
|
27
|
-
render_svg "<svg
|
10
|
+
def template
|
11
|
+
"<svg
|
28
12
|
viewBox='0 0 #{SIZE} #{SIZE}'
|
29
13
|
fill='none'
|
30
14
|
xmlns='http://www.w3.org/2000/svg'
|
@@ -73,5 +57,17 @@ module BoringAvatar
|
|
73
57
|
</g>
|
74
58
|
</svg>"
|
75
59
|
end
|
60
|
+
|
61
|
+
def properties
|
62
|
+
@properties ||= (0..ELEMENTS).to_a.each_with_object([]) do |i, arr|
|
63
|
+
arr << {
|
64
|
+
color: Util.get_random_color(colors, num_from_name + i, range),
|
65
|
+
translateX: Util.get_unit(num_from_name * (i + 1), (SIZE/2 - (i + 17)), 1),
|
66
|
+
translateY: Util.get_unit(num_from_name * (i + 1), (SIZE/2 - (i + 17)), 2),
|
67
|
+
rotate: Util.get_unit(num_from_name * (i + 1), 360),
|
68
|
+
isSquare: Util.get_boolean(num_from_name, 2)
|
69
|
+
}
|
70
|
+
end
|
71
|
+
end
|
76
72
|
end
|
77
73
|
end
|
@@ -2,47 +2,18 @@
|
|
2
2
|
|
3
3
|
module BoringAvatar
|
4
4
|
class Beam < Base
|
5
|
-
SIZE = 36
|
6
|
-
|
7
|
-
def generate
|
8
|
-
template(data)
|
9
|
-
end
|
5
|
+
SIZE = 36.freeze
|
10
6
|
|
11
7
|
private
|
12
8
|
|
13
|
-
def
|
14
|
-
|
15
|
-
|
16
|
-
wrapperTranslateX = preTranslateX < 5 ? (preTranslateX + SIZE/9) : preTranslateX
|
17
|
-
preTranslateY = Util.get_unit(num_from_name, 10, 2)
|
18
|
-
wrapperTranslateY = preTranslateY < 5 ? (preTranslateY + SIZE/9) : preTranslateY
|
19
|
-
|
20
|
-
{
|
21
|
-
wrapperColor: wrapperColor,
|
22
|
-
faceColor: Util.get_contrast(wrapperColor),
|
23
|
-
backgroundColor: Util.get_random_color(colors, num_from_name + 13, range),
|
24
|
-
wrapperTranslateX: wrapperTranslateX,
|
25
|
-
wrapperTranslateY: wrapperTranslateY,
|
26
|
-
wrapperRotate: Util.get_unit(num_from_name, 360),
|
27
|
-
wrapperScale: 1 + (Util.get_unit(num_from_name, SIZE / 12) / 10.to_f),
|
28
|
-
isMouthOpen: Util.get_boolean(num_from_name, 2),
|
29
|
-
isCircle: Util.get_boolean(num_from_name, 1),
|
30
|
-
eyeSpread: Util.get_unit(num_from_name, 5) ,
|
31
|
-
mouthSpread: Util.get_unit(num_from_name, 3),
|
32
|
-
faceRotate: Util.get_unit(num_from_name, 10, 3),
|
33
|
-
faceTranslateX: wrapperTranslateX > (SIZE/6) ? wrapperTranslateX/2.to_f : Util.get_unit(num_from_name, 8, 1),
|
34
|
-
faceTranslateY: wrapperTranslateY > (SIZE/6) ? wrapperTranslateY/2.to_f : Util.get_unit(num_from_name, 7, 2)
|
35
|
-
}
|
36
|
-
end
|
37
|
-
|
38
|
-
def template(data)
|
39
|
-
mouth = if data[:isMouthOpen]
|
40
|
-
"<path d='M15 #{19 + data[:mouthSpread]} c2 1 4 1 6 0' stroke='#{data[:faceColor]}' fill='none' stroke-linecap='round' />"
|
9
|
+
def template
|
10
|
+
mouth = if properties[:isMouthOpen]
|
11
|
+
"<path d='M15 #{19 + properties[:mouthSpread]} c2 1 4 1 6 0' stroke='#{properties[:faceColor]}' fill='none' stroke-linecap='round' />"
|
41
12
|
else
|
42
|
-
"<path d='M13, #{19 +
|
13
|
+
"<path d='M13, #{19 + properties[:mouthSpread]} a1,0.75 0 0,0 10,0' fill='#{properties[:faceColor]}' />"
|
43
14
|
end
|
44
15
|
|
45
|
-
|
16
|
+
"<svg
|
46
17
|
viewBox='0 0 #{SIZE} #{SIZE}'
|
47
18
|
fill='none'
|
48
19
|
xmlns='http://www.w3.org/2000/svg'
|
@@ -67,24 +38,49 @@ module BoringAvatar
|
|
67
38
|
width='#{SIZE}'
|
68
39
|
height='#{SIZE}'
|
69
40
|
rx='20'
|
70
|
-
fill='#{
|
41
|
+
fill='#{properties[:backgroundColor]}'
|
71
42
|
/>
|
72
43
|
<rect
|
73
44
|
x='0'
|
74
45
|
y='0'
|
75
46
|
width='#{SIZE}'
|
76
47
|
height='#{SIZE}'
|
77
|
-
transform='translate(#{
|
78
|
-
fill='#{
|
79
|
-
rx='#{
|
48
|
+
transform='translate(#{properties[:wrapperTranslateX]} #{properties[:wrapperTranslateY]}) rotate(#{properties[:wrapperRotate]} #{SIZE / 2} #{SIZE / 2}) scale(#{properties[:wrapperScale]})'
|
49
|
+
fill='#{properties[:wrapperColor]}'
|
50
|
+
rx='#{properties[:isCircle] ? SIZE : SIZE/6}'
|
80
51
|
/>
|
81
|
-
<g transform='translate(#{
|
52
|
+
<g transform='translate(#{properties[:faceTranslateX]} #{properties[:faceTranslateY]}) rotate(#{properties[:faceRotate]} #{SIZE / 2} #{SIZE / 2})'>
|
82
53
|
#{mouth}
|
83
|
-
<rect x='#{14 -
|
84
|
-
<rect x='#{20 +
|
54
|
+
<rect x='#{14 - properties[:eyeSpread]}' y='14' width='1.5' height='2' rx='1' stroke='none' fill='#{properties[:faceColor]}' />
|
55
|
+
<rect x='#{20 + properties[:eyeSpread]}' y='14' width='1.5' height='2' rx='1' stroke='none' fill='#{properties[:faceColor]}' />
|
85
56
|
</g>
|
86
57
|
</g>
|
87
58
|
</svg>"
|
88
59
|
end
|
60
|
+
|
61
|
+
def properties
|
62
|
+
wrapperColor = Util.get_random_color(colors, num_from_name, range)
|
63
|
+
preTranslateX = Util.get_unit(num_from_name, 10, 1)
|
64
|
+
wrapperTranslateX = preTranslateX < 5 ? (preTranslateX + SIZE/9) : preTranslateX
|
65
|
+
preTranslateY = Util.get_unit(num_from_name, 10, 2)
|
66
|
+
wrapperTranslateY = preTranslateY < 5 ? (preTranslateY + SIZE/9) : preTranslateY
|
67
|
+
|
68
|
+
@properties ||= {
|
69
|
+
wrapperColor: wrapperColor,
|
70
|
+
faceColor: Util.get_contrast(wrapperColor),
|
71
|
+
backgroundColor: Util.get_random_color(colors, num_from_name + 13, range),
|
72
|
+
wrapperTranslateX: wrapperTranslateX,
|
73
|
+
wrapperTranslateY: wrapperTranslateY,
|
74
|
+
wrapperRotate: Util.get_unit(num_from_name, 360),
|
75
|
+
wrapperScale: 1 + (Util.get_unit(num_from_name, SIZE / 12) / 10.to_f),
|
76
|
+
isMouthOpen: Util.get_boolean(num_from_name, 2),
|
77
|
+
isCircle: Util.get_boolean(num_from_name, 1),
|
78
|
+
eyeSpread: Util.get_unit(num_from_name, 5) ,
|
79
|
+
mouthSpread: Util.get_unit(num_from_name, 3),
|
80
|
+
faceRotate: Util.get_unit(num_from_name, 10, 3),
|
81
|
+
faceTranslateX: wrapperTranslateX > (SIZE/6) ? wrapperTranslateX/2.to_f : Util.get_unit(num_from_name, 8, 1),
|
82
|
+
faceTranslateY: wrapperTranslateY > (SIZE/6) ? wrapperTranslateY/2.to_f : Util.get_unit(num_from_name, 7, 2)
|
83
|
+
}
|
84
|
+
end
|
89
85
|
end
|
90
86
|
end
|
@@ -2,29 +2,13 @@
|
|
2
2
|
|
3
3
|
module BoringAvatar
|
4
4
|
class Marble < Base
|
5
|
-
ELEMENTS = 3
|
6
|
-
SIZE = 80
|
7
|
-
|
8
|
-
def generate
|
9
|
-
template(generate_colors)
|
10
|
-
end
|
5
|
+
ELEMENTS = 3.freeze
|
6
|
+
SIZE = 80.freeze
|
11
7
|
|
12
8
|
private
|
13
9
|
|
14
|
-
def
|
15
|
-
|
16
|
-
arr << {
|
17
|
-
color: Util.get_random_color(colors, num_from_name + i, range),
|
18
|
-
translateX: Util.get_unit(num_from_name * (i + 1), SIZE / 10, 1),
|
19
|
-
translateY: Util.get_unit(num_from_name * (i + 1), SIZE / 10, 2),
|
20
|
-
scale: 1.2 + (Util.get_unit(num_from_name * (i + 1), SIZE / 20.to_f) / 10),
|
21
|
-
rotate: Util.get_unit(num_from_name * (i + 1), 360, 1)
|
22
|
-
}
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def template(properties)
|
27
|
-
render_svg "<svg
|
10
|
+
def template
|
11
|
+
"<svg
|
28
12
|
viewBox='0 0 #{SIZE} #{SIZE}'
|
29
13
|
fill='none'
|
30
14
|
xmlns='http://www.w3.org/2000/svg'
|
@@ -74,5 +58,17 @@ module BoringAvatar
|
|
74
58
|
</defs>
|
75
59
|
</svg>"
|
76
60
|
end
|
61
|
+
|
62
|
+
def properties
|
63
|
+
@properties ||= (0..ELEMENTS).to_a.each_with_object([]) do |i, arr|
|
64
|
+
arr << {
|
65
|
+
color: Util.get_random_color(colors, num_from_name + i, range),
|
66
|
+
translateX: Util.get_unit(num_from_name * (i + 1), SIZE / 10, 1),
|
67
|
+
translateY: Util.get_unit(num_from_name * (i + 1), SIZE / 10, 2),
|
68
|
+
scale: 1.2 + (Util.get_unit(num_from_name * (i + 1), SIZE / 20.to_f) / 10),
|
69
|
+
rotate: Util.get_unit(num_from_name * (i + 1), 360, 1)
|
70
|
+
}
|
71
|
+
end
|
72
|
+
end
|
77
73
|
end
|
78
74
|
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module BoringAvatar
|
4
|
+
class Ring < Base
|
5
|
+
SIZE = 90.freeze
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
def template
|
10
|
+
"<svg
|
11
|
+
viewBox='0 0 #{SIZE} #{SIZE}'
|
12
|
+
fill='none'
|
13
|
+
role='img'
|
14
|
+
xmlns='http://www.w3.org/2000/svg'
|
15
|
+
width='#{size}'
|
16
|
+
height='#{size}'>
|
17
|
+
<mask
|
18
|
+
id='mask__ring'
|
19
|
+
maskUnits='userSpaceOnUse'
|
20
|
+
x='0'
|
21
|
+
y='0'
|
22
|
+
width='#{SIZE}'
|
23
|
+
height='#{SIZE}'>
|
24
|
+
<rect
|
25
|
+
width='#{SIZE}'
|
26
|
+
height='#{SIZE}'
|
27
|
+
rx='180'
|
28
|
+
fill='#FFFFFF'>
|
29
|
+
</rect>
|
30
|
+
</mask>
|
31
|
+
<g mask='url(#mask__ring)'>
|
32
|
+
<path d='M0 0h90v45H0z' fill='#{colors[0]}'></path>
|
33
|
+
<path d='M0 45h90v45H0z' fill='#{colors[1]}'></path>
|
34
|
+
<path d='M83 45a38 38 0 00-76 0h76z' fill='#{colors[1]}'></path>
|
35
|
+
<path d='M83 45a38 38 0 01-76 0h76z' fill='#{colors[2]}'></path>
|
36
|
+
<path d='M77 45a32 32 0 10-64 0h64z' fill='#{colors[2]}'></path>
|
37
|
+
<path d='M77 45a32 32 0 11-64 0h64z' fill='#{colors[3]}'></path>
|
38
|
+
<path d='M71 45a26 26 0 00-52 0h52z' fill='#{colors[3]}'></path>
|
39
|
+
<path d='M71 45a26 26 0 01-52 0h52z' fill='#{colors[0]}'></path>
|
40
|
+
<circle cx='45' cy='45' r='23' fill='#{colors[4]}'></circle>
|
41
|
+
</g>
|
42
|
+
</svg>"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -2,27 +2,13 @@
|
|
2
2
|
|
3
3
|
module BoringAvatar
|
4
4
|
class Sunset < Base
|
5
|
-
ELEMENTS = 4
|
6
|
-
SIZE = 80
|
7
|
-
|
8
|
-
def generate
|
9
|
-
template(avatar_name, generate_colors)
|
10
|
-
end
|
5
|
+
ELEMENTS = 4.freeze
|
6
|
+
SIZE = 80.freeze
|
11
7
|
|
12
8
|
private
|
13
9
|
|
14
|
-
def
|
15
|
-
|
16
|
-
end
|
17
|
-
|
18
|
-
def generate_colors
|
19
|
-
(0..ELEMENTS).to_a.each_with_object([]) do |index, arr|
|
20
|
-
arr << Util.get_random_color(colors, num_from_name + index, range)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def template(name, kolors)
|
25
|
-
render_svg "<svg
|
10
|
+
def template
|
11
|
+
"<svg
|
26
12
|
viewBox='0 0 #{SIZE} #{SIZE}'
|
27
13
|
fill='none'
|
28
14
|
xmlns='http://www.w3.org/2000/svg'
|
@@ -38,32 +24,42 @@ module BoringAvatar
|
|
38
24
|
<circle cx='#{SIZE/2}' cy='#{SIZE/2}' r='#{SIZE/2}' fill='white' />
|
39
25
|
</mask>
|
40
26
|
<g mask='url(#mask__sunset)'>
|
41
|
-
<path fill='url(#gradient_paint0_linear_#{
|
42
|
-
<path fill='url(#gradient_paint1_linear_#{
|
27
|
+
<path fill='url(#gradient_paint0_linear_#{avatar_name})' d='M0 0h80v40H0z' />
|
28
|
+
<path fill='url(#gradient_paint1_linear_#{avatar_name})' d='M0 40h80v40H0z' />
|
43
29
|
</g>
|
44
30
|
<defs>
|
45
31
|
<linearGradient
|
46
|
-
id='gradient_paint0_linear_#{
|
32
|
+
id='gradient_paint0_linear_#{avatar_name}'
|
47
33
|
x1='#{SIZE/2}'
|
48
34
|
y1='0'
|
49
35
|
x2='#{SIZE/2}'
|
50
36
|
y2='#{SIZE/2}'
|
51
37
|
gradientUnits='userSpaceOnUse'>
|
52
|
-
<stop stop-Color='#{
|
53
|
-
<stop offset='1' stop-Color='#{
|
38
|
+
<stop stop-Color='#{color_palette[0]}' />
|
39
|
+
<stop offset='1' stop-Color='#{color_palette[1]}' />
|
54
40
|
</linearGradient>
|
55
41
|
<linearGradient
|
56
|
-
id='gradient_paint1_linear_#{
|
42
|
+
id='gradient_paint1_linear_#{avatar_name}'
|
57
43
|
x1='#{SIZE/2}'
|
58
44
|
y1='#{SIZE/2}'
|
59
45
|
x2='#{SIZE/2}'
|
60
46
|
y2=#{SIZE}
|
61
47
|
gradientUnits='userSpaceOnUse'>
|
62
|
-
<stop stop-Color='#{
|
63
|
-
<stop offset='1' stop-Color='#{
|
48
|
+
<stop stop-Color='#{color_palette[2]}' />
|
49
|
+
<stop offset='1' stop-Color='#{color_palette[3]}' />
|
64
50
|
</linearGradient>
|
65
51
|
</defs>
|
66
52
|
</svg>"
|
67
53
|
end
|
54
|
+
|
55
|
+
def avatar_name
|
56
|
+
@avatar_name ||= name.strip.gsub(" ", "")
|
57
|
+
end
|
58
|
+
|
59
|
+
def color_palette
|
60
|
+
@color_palette ||= (0..ELEMENTS).to_a.each_with_object([]) do |index, arr|
|
61
|
+
arr << Util.get_random_color(colors, num_from_name + index, range)
|
62
|
+
end
|
63
|
+
end
|
68
64
|
end
|
69
65
|
end
|
data/lib/boring_avatar/util.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "json"
|
4
|
+
|
3
5
|
module Util
|
4
6
|
class << self
|
5
7
|
def get_number(name)
|
@@ -33,5 +35,15 @@ module Util
|
|
33
35
|
yiq = ((red * 299) + (green * 587) + (blue * 114)) / 1000
|
34
36
|
yiq > 128 ? "black" : "white"
|
35
37
|
end
|
38
|
+
|
39
|
+
def random_palette
|
40
|
+
color_palettes[(0..99).to_a.sample]
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def color_palettes
|
46
|
+
@color_palettes ||= JSON.parse(File.read("./color_palettes.json"))
|
47
|
+
end
|
36
48
|
end
|
37
49
|
end
|
data/lib/boring_avatar.rb
CHANGED
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: boring_avatar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Olivier
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-09-22 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description: This is a simple Ruby implementation of Boring Avatars
|
13
|
+
description: This is a simple Ruby implementation of Boring Avatars library
|
14
14
|
email:
|
15
15
|
- olivier@yafoy.com
|
16
16
|
executables: []
|
@@ -29,11 +29,13 @@ files:
|
|
29
29
|
- bin/console
|
30
30
|
- bin/setup
|
31
31
|
- boring_avatar.gemspec
|
32
|
+
- color_palettes.json
|
32
33
|
- lib/boring_avatar.rb
|
33
34
|
- lib/boring_avatar/avatar/base.rb
|
34
35
|
- lib/boring_avatar/avatar/bauhaus.rb
|
35
36
|
- lib/boring_avatar/avatar/beam.rb
|
36
37
|
- lib/boring_avatar/avatar/marble.rb
|
38
|
+
- lib/boring_avatar/avatar/ring.rb
|
37
39
|
- lib/boring_avatar/avatar/sunset.rb
|
38
40
|
- lib/boring_avatar/util.rb
|
39
41
|
- lib/boring_avatar/version.rb
|
@@ -59,7 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
59
61
|
- !ruby/object:Gem::Version
|
60
62
|
version: '0'
|
61
63
|
requirements: []
|
62
|
-
rubygems_version: 3.
|
64
|
+
rubygems_version: 3.1.6
|
63
65
|
signing_key:
|
64
66
|
specification_version: 4
|
65
67
|
summary: Generate Boring Avatars
|