boring_avatar 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c2a46fe1278147345dfd8002ec30e3344552a68ad2638eb3f3c60874402dafe3
4
+ data.tar.gz: 47f489ae52f0c744bda5112db493f51d2a975cda9f5774549d3a340540603f49
5
+ SHA512:
6
+ metadata.gz: 731b080715c87cbbd86c5e272f41f93cc3828221631058cda617fbf83e96e76f9acb5ba415740a5ecc470cb39796e42a81f7ceda5e429f597386b2e9bdbbcf86
7
+ data.tar.gz: 1fe3bc4de719581846a13d5dbda1866a2d8047619b8fbd9e2187e68075b5805dcaea1df4ccf9ea7a5a23664fa69916561404dcf7ee0e49068f6479b6a6e7a97a
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ *.gem
2
+ /.bundle/
3
+ /.yardoc
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .DS_Store
11
+ *.log
12
+ TODO.md
13
+ .byebug_history
@@ -0,0 +1,20 @@
1
+ version: v1.0
2
+ name: Initial Pipeline
3
+ agent:
4
+ machine:
5
+ type: e1-standard-2
6
+ os_image: ubuntu1804
7
+ blocks:
8
+ - name: CI
9
+ task:
10
+ jobs:
11
+ - name: Test
12
+ commands:
13
+ - checkout
14
+ - sem-version ruby 3.0.1
15
+ - cache restore
16
+ - bundle config set --local deployment 'true'
17
+ - bundle config set --local path 'vendor/bundle'
18
+ - bundle install
19
+ - cache store
20
+ - bundle exec rake
data/.tool-versions ADDED
@@ -0,0 +1 @@
1
+ ruby 3.0.1
data/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ # Changelog
2
+
3
+ ## 0.1.1 / 2021-06-03
4
+
5
+ - Renamed the gem to `boring_avatar`
6
+
7
+ ## 0.1.0 / 2021-06-03
8
+
9
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in BoringAvatar.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "minitest", "~> 5.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,22 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ boring_avatar (0.1.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ minitest (5.14.4)
10
+ rake (12.3.3)
11
+
12
+ PLATFORMS
13
+ x86_64-darwin-20
14
+ x86_64-linux
15
+
16
+ DEPENDENCIES
17
+ boring_avatar!
18
+ minitest (~> 5.0)
19
+ rake (~> 12.0)
20
+
21
+ BUNDLED WITH
22
+ 2.2.15
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 olimart
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,52 @@
1
+ # BoringAvatar
2
+
3
+ [![Build Status](https://yafoy.semaphoreci.com/badges/boring-avatar/branches/master.svg?style=shields)](https://yafoy.semaphoreci.com/projects/boring-avatar)
4
+
5
+ This is a Ruby implementation of [Boring Avatars](https://boringavatars.com)
6
+
7
+ Currently only supporting the following variants:
8
+ - Bauhaus
9
+ - Beam
10
+ - Marble
11
+ - Sunset
12
+
13
+ ## Installation
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ ```ruby
18
+ gem "boring_avatar"
19
+ ```
20
+
21
+ And then execute:
22
+
23
+ $ bundle install
24
+
25
+ Or install it yourself as:
26
+
27
+ $ gem install boring_avatar
28
+
29
+ ## Usage
30
+
31
+ ```ruby
32
+ BoringAvatar::Bauhaus.generate
33
+ BoringAvatar::Beam.generate(name: "John Doe")
34
+ BoringAvatar::Marble.generate(name: "John Doe", size: 40)
35
+ BoringAvatar::Sunset.generate(name: "John Doe", size: 40, colors: %w[#a3a948 #edb92e #f85931 #ce1836 #009989])
36
+ ```
37
+
38
+ There is also an [online service](https://github.com/hihayk/boring-avatars-service/) should you wish to build a wrapper around the API.
39
+
40
+ ## Development
41
+
42
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
43
+
44
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
45
+
46
+ ## Contributing
47
+
48
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/BoringAvatar.
49
+
50
+ ## License
51
+
52
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "boring_avatar"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,27 @@
1
+ require_relative 'lib/boring_avatar/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "boring_avatar"
5
+ spec.version = BoringAvatar::VERSION
6
+ spec.authors = ["Olivier"]
7
+ spec.email = ["olivier@yafoy.com"]
8
+
9
+ spec.summary = "Generate Boring Avatars"
10
+ spec.description = "This is a simple Ruby implementation of Boring Avatars"
11
+ spec.homepage = "https://github.com/olimart/boring_avatar"
12
+ spec.license = "MIT"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
14
+
15
+ spec.metadata["homepage_uri"] = spec.homepage
16
+ spec.metadata["source_code_uri"] = "https://github.com/olimart/boring_avatar"
17
+ spec.metadata["changelog_uri"] = "https://github.com/olimart/boring_avatar/blob/master/CHANGELOG.md"
18
+
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
22
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
+ end
24
+ spec.bindir = "exe"
25
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ["lib"]
27
+ end
@@ -0,0 +1,13 @@
1
+ require "boring_avatar/version"
2
+
3
+ require "boring_avatar/util"
4
+ require "boring_avatar/avatar/base"
5
+ require "boring_avatar/avatar/beam"
6
+ require "boring_avatar/avatar/bauhaus"
7
+ require "boring_avatar/avatar/marble"
8
+ require "boring_avatar/avatar/sunset"
9
+
10
+ module BoringAvatar
11
+ class Error < StandardError; end
12
+ class NotImplementedError < StandardError; end
13
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BoringAvatar
4
+ class Base
5
+ COLORS = %w[#92a1c6 #146a7c #f0ab3d #c271b4 #c20d90]
6
+ NAME = "Clara Barton"
7
+ SIZE = 40
8
+
9
+ attr_reader :colors, :name, :size, :opts, :num_from_name, :range
10
+
11
+ def initialize(colors: COLORS, name: NAME, size: SIZE, **opts)
12
+ @colors = colors
13
+ @name = name
14
+ @size = size
15
+ @opts = opts
16
+ @num_from_name = Util.get_number(name)
17
+ @range = colors.length
18
+ end
19
+
20
+ def generate
21
+ raise NotImplementedError
22
+ end
23
+
24
+ private
25
+
26
+ def render_svg(text)
27
+ text
28
+ .gsub(/>\s+</, "><")
29
+ .gsub(/\s+/, " ")
30
+ .strip
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,77 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BoringAvatar
4
+ class Bauhaus < Base
5
+ ELEMENTS = 4
6
+ SIZE = 80
7
+
8
+ def generate
9
+ template(generate_colors)
10
+ end
11
+
12
+ private
13
+
14
+ def generate_colors
15
+ (0..ELEMENTS).to_a.each_with_object([]) do |i, arr|
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
28
+ viewBox='0 0 #{SIZE} #{SIZE}'
29
+ fill='none'
30
+ xmlns='http://www.w3.org/2000/svg'
31
+ width='#{size}'
32
+ height='#{size}'>
33
+ <mask
34
+ id='mask__bauhaus'
35
+ maskUnits='userSpaceOnUse'
36
+ x='0'
37
+ y='0'
38
+ width='#{SIZE}'
39
+ height='#{SIZE}'>
40
+ <rect width='#{SIZE}' height='#{SIZE}' rx='#{SIZE / 2}' fill='#fff' />
41
+ </mask>
42
+ <g mask='url(#mask__bauhaus)'>
43
+ <rect
44
+ width='#{SIZE}'
45
+ height='#{SIZE}'
46
+ rx='#{SIZE / 2}'
47
+ fill='#{properties[0][:color]}'
48
+ />
49
+ <rect
50
+ x='#{(SIZE - 60) / 2}'
51
+ y='#{(SIZE - 20) / 2}'
52
+ width='#{SIZE}'
53
+ height='#{properties[1][:isSquare] ? SIZE : SIZE / 8}'
54
+ fill='#{properties[1][:color]}'
55
+ transform='translate(#{properties[1][:translateX]} #{properties[1][:translateY]}) rotate(#{properties[1][:rotate]} #{SIZE / 2} #{SIZE / 2})'
56
+ />
57
+ <circle
58
+ cx='#{SIZE / 2}'
59
+ cy='#{SIZE / 2}'
60
+ fill='#{properties[2][:color]}'
61
+ r='#{SIZE / 5}'
62
+ transform='translate(#{properties[2][:translateX]} #{properties[2][:translateY]})'
63
+ />
64
+ <line
65
+ x1='0'
66
+ y1='#{SIZE / 2}'
67
+ x2='#{SIZE}'
68
+ y2='#{SIZE / 2}'
69
+ stroke-width='2'
70
+ stroke='#{properties[3][:color]}'
71
+ transform='translate(#{properties[3][:translateX]} #{properties[3][:translateY]}) rotate(#{properties[3][:rotate]} #{SIZE / 2} #{SIZE / 2})'
72
+ />
73
+ </g>
74
+ </svg>"
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,90 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BoringAvatar
4
+ class Beam < Base
5
+ SIZE = 36
6
+
7
+ def generate
8
+ template(data)
9
+ end
10
+
11
+ private
12
+
13
+ def data
14
+ wrapperColor = Util.get_random_color(colors, num_from_name, range)
15
+ preTranslateX = Util.get_unit(num_from_name, 10, 1)
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' />"
41
+ else
42
+ "<path d='M13, #{19 + data[:mouthSpread]} a1,0.75 0 0,0 10,0' fill='#{data[:faceColor]}' />"
43
+ end
44
+
45
+ render_svg "<svg
46
+ viewBox='0 0 #{SIZE} #{SIZE}'
47
+ fill='none'
48
+ xmlns='http://www.w3.org/2000/svg'
49
+ width='#{size}'
50
+ height='#{size}'>
51
+ <mask
52
+ id='mask__beam'
53
+ maskUnits='userSpaceOnUse'
54
+ x='0'
55
+ y='0'
56
+ width='#{SIZE}'
57
+ height='#{SIZE}'>
58
+ <rect
59
+ width='#{SIZE}'
60
+ height='#{SIZE}'
61
+ rx='20'
62
+ fill='white'
63
+ />
64
+ </mask>
65
+ <g mask='url(#mask__beam)' fill='transparent'>
66
+ <rect
67
+ width='#{SIZE}'
68
+ height='#{SIZE}'
69
+ rx='20'
70
+ fill='#{data[:backgroundColor]}'
71
+ />
72
+ <rect
73
+ x='0'
74
+ y='0'
75
+ width='#{SIZE}'
76
+ height='#{SIZE}'
77
+ transform='translate(#{data[:wrapperTranslateX]} #{data[:wrapperTranslateY]}) rotate(#{data[:wrapperRotate]} #{SIZE / 2} #{SIZE / 2}) scale(#{data[:wrapperScale]})'
78
+ fill='#{data[:wrapperColor]}'
79
+ rx='#{data[:isCircle] ? SIZE : SIZE/6}'
80
+ />
81
+ <g transform='translate(#{data[:faceTranslateX]} #{data[:faceTranslateY]}) rotate(#{data[:faceRotate]} #{SIZE / 2} #{SIZE / 2})'>
82
+ #{mouth}
83
+ <rect x='#{14 - data[:eyeSpread]}' y='14' width='1.5' height='2' rx='1' stroke='none' fill='#{data[:faceColor]}' />
84
+ <rect x='#{20 + data[:eyeSpread]}' y='14' width='1.5' height='2' rx='1' stroke='none' fill='#{data[:faceColor]}' />
85
+ </g>
86
+ </g>
87
+ </svg>"
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BoringAvatar
4
+ class Marble < Base
5
+ ELEMENTS = 3
6
+ SIZE = 80
7
+
8
+ def generate
9
+ template(generate_colors)
10
+ end
11
+
12
+ private
13
+
14
+ def generate_colors
15
+ (0..ELEMENTS).to_a.each_with_object([]) do |i, arr|
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
28
+ viewBox='0 0 #{SIZE} #{SIZE}'
29
+ fill='none'
30
+ xmlns='http://www.w3.org/2000/svg'
31
+ width='#{size}'
32
+ height='#{size}'>
33
+ <mask
34
+ id='mask__marble'
35
+ maskUnits='userSpaceOnUse'
36
+ x='0'
37
+ y='0'
38
+ width='#{SIZE}'
39
+ height='#{SIZE}'>
40
+ <path
41
+ d='M80 40C80 17.909 62.091 0 40 0S0 17.909 0 40s17.909 40 40 40 40-17.909 40-40z'
42
+ fill='#fff'
43
+ />
44
+ </mask>
45
+ <g mask='url(#mask__marble)'>
46
+ <path
47
+ d='M80 40C80 17.909 62.091 0 40 0S0 17.909 0 40s17.909 40 40 40 40-17.909 40-40z'
48
+ fill='#{properties[0][:color]}'
49
+ />
50
+ <path
51
+ filter='url(#prefix__filter0_f)'
52
+ d='M32.414 59.35L50.376 70.5H72.5v-71H33.728L26.5 13.381l19.057 27.08L32.414 59.35z'
53
+ fill='#{properties[1][:color]}'
54
+ transform='translate(#{properties[1][:translateX]} #{properties[1][:translateY]}) rotate(#{properties[1][:rotate]} #{SIZE/2} #{SIZE/2}) scale(#{properties[2][:scale]})'
55
+ />
56
+ <path
57
+ filter='url(#prefix__filter0_f)'
58
+ style='mix-blend-mode: overlay;'
59
+ d='M22.216 24L0 46.75l14.108 38.129L78 86l-3.081-59.276-22.378 4.005 12.972 20.186-23.35 27.395L22.215 24z'
60
+ fill='#{properties[2][:color]}'
61
+ transform='translate(#{properties[2][:translateX]} #{properties[2][:translateY]}) rotate(#{properties[2][:rotate]} #{SIZE/2} #{SIZE/2}) scale(#{properties[2][:scale]})'
62
+ />
63
+ </g>
64
+ <defs>
65
+ <filter
66
+ id='prefix__filter0_f'
67
+ filterUnits='userSpaceOnUse'
68
+ colorInterpolationFilters='sRGB'
69
+ >
70
+ <feFlood flood-opacity='0' result='BackgroundImageFix' />
71
+ <feBlend in='SourceGraphic' in2='BackgroundImageFix' result='shape' />
72
+ <feGaussianBlur stdDeviation='7' result='effect1_foregroundBlur' />
73
+ </filter>
74
+ </defs>
75
+ </svg>"
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BoringAvatar
4
+ class Sunset < Base
5
+ ELEMENTS = 4
6
+ SIZE = 80
7
+
8
+ def generate
9
+ template(avatar_name, generate_colors)
10
+ end
11
+
12
+ private
13
+
14
+ def avatar_name
15
+ @avatar_name ||= name.strip.gsub(" ", "")
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
26
+ viewBox='0 0 #{SIZE} #{SIZE}'
27
+ fill='none'
28
+ xmlns='http://www.w3.org/2000/svg'
29
+ width='#{size}'
30
+ height='#{size}'>
31
+ <mask
32
+ id='mask__sunset'
33
+ maskUnits='userSpaceOnUse'
34
+ x='0'
35
+ y='0'
36
+ width='#{SIZE}'
37
+ height='#{SIZE}'>
38
+ <circle cx='#{SIZE/2}' cy='#{SIZE/2}' r='#{SIZE/2}' fill='white' />
39
+ </mask>
40
+ <g mask='url(#mask__sunset)'>
41
+ <path fill='url(#gradient_paint0_linear_#{name})' d='M0 0h80v40H0z' />
42
+ <path fill='url(#gradient_paint1_linear_#{name})' d='M0 40h80v40H0z' />
43
+ </g>
44
+ <defs>
45
+ <linearGradient
46
+ id='gradient_paint0_linear_#{name}'
47
+ x1='#{SIZE/2}'
48
+ y1='0'
49
+ x2='#{SIZE/2}'
50
+ y2='#{SIZE/2}'
51
+ gradientUnits='userSpaceOnUse'>
52
+ <stop stop-Color='#{kolors[0]}' />
53
+ <stop offset='1' stop-Color='#{kolors[1]}' />
54
+ </linearGradient>
55
+ <linearGradient
56
+ id='gradient_paint1_linear_#{name}'
57
+ x1='#{SIZE/2}'
58
+ y1='#{SIZE/2}'
59
+ x2='#{SIZE/2}'
60
+ y2=#{SIZE}
61
+ gradientUnits='userSpaceOnUse'>
62
+ <stop stop-Color='#{kolors[2]}' />
63
+ <stop offset='1' stop-Color='#{kolors[3]}' />
64
+ </linearGradient>
65
+ </defs>
66
+ </svg>"
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Util
4
+ class << self
5
+ def get_number(name)
6
+ name.chars
7
+ .map(&:ord)
8
+ .inject(:+)
9
+ end
10
+
11
+ def get_random_color(colors, number, range)
12
+ colors[number % range]
13
+ end
14
+
15
+ def get_unit(number, range, index = nil)
16
+ value = number % range
17
+ if index && (get_digit(number, index) % 2) == 0
18
+ return -value
19
+ end
20
+ value
21
+ end
22
+
23
+ def get_digit(number, ntn)
24
+ ((number / (10 ** ntn)) % 10).to_i
25
+ end
26
+
27
+ def get_boolean(number, ntn)
28
+ !(get_digit(number, ntn) % 2 > 0)
29
+ end
30
+
31
+ def get_contrast(hex)
32
+ red, green, blue = hex.delete_prefix("#").scan(/../).map { |c| c.to_i(16) }
33
+ yiq = ((red * 299) + (green * 587) + (blue * 114)) / 1000
34
+ yiq > 128 ? "black" : "white"
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,3 @@
1
+ module BoringAvatar
2
+ VERSION = "0.1.1"
3
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: boring_avatar
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Olivier
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-06-04 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: This is a simple Ruby implementation of Boring Avatars
14
+ email:
15
+ - olivier@yafoy.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".gitignore"
21
+ - ".semaphore/semaphore.yml"
22
+ - ".tool-versions"
23
+ - CHANGELOG.md
24
+ - Gemfile
25
+ - Gemfile.lock
26
+ - LICENSE.txt
27
+ - README.md
28
+ - Rakefile
29
+ - bin/console
30
+ - bin/setup
31
+ - boring_avatar.gemspec
32
+ - lib/boring_avatar.rb
33
+ - lib/boring_avatar/avatar/base.rb
34
+ - lib/boring_avatar/avatar/bauhaus.rb
35
+ - lib/boring_avatar/avatar/beam.rb
36
+ - lib/boring_avatar/avatar/marble.rb
37
+ - lib/boring_avatar/avatar/sunset.rb
38
+ - lib/boring_avatar/util.rb
39
+ - lib/boring_avatar/version.rb
40
+ homepage: https://github.com/olimart/boring_avatar
41
+ licenses:
42
+ - MIT
43
+ metadata:
44
+ homepage_uri: https://github.com/olimart/boring_avatar
45
+ source_code_uri: https://github.com/olimart/boring_avatar
46
+ changelog_uri: https://github.com/olimart/boring_avatar/blob/master/CHANGELOG.md
47
+ post_install_message:
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: 2.7.0
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ requirements: []
62
+ rubygems_version: 3.2.15
63
+ signing_key:
64
+ specification_version: 4
65
+ summary: Generate Boring Avatars
66
+ test_files: []