icodi 0.1.3 → 0.1.4

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: ed662658e812ed352bae13ab22ade162554042af8894e4ac6b979cb5f5b33d49
4
- data.tar.gz: 68f723bc2f69ac46f051796ffcf69713c5e1c1d2d4d6cb45902afdcbffb7872b
3
+ metadata.gz: f552185f36c92756e8ebb28fe15ca0ac2efdf821934ada7e115fef570658687f
4
+ data.tar.gz: 3cc2ff20a4fbfa8137a75e76651e1362af861712a0099cb455aca9a0e7632996
5
5
  SHA512:
6
- metadata.gz: 115aa2c08283428ea5883737b118b4bbd4f6dd29996964cdfcf6fd1e9c7abdc8212708b6bbaf446048e692d105cf6858e6aa2ff54b1d944a056620efefbf0d73
7
- data.tar.gz: 211be6a5f5d6b96c8e2e2e22d9a5b9fbcebaa3594d0f624582a4a584dbb40a5aa352b574ed38245fcfb022a5641b9e44f5ec505490dbe7bad2b1a73ab1ad0150
6
+ metadata.gz: a8b4b6538723c593eecb1e87a3b550a855a412c48fc81357e9031bef096585828e47f74e1aa4db2eecb62925651ab21380632412ee61310a5be434d6bdf6cfe9
7
+ data.tar.gz: 709621cd1d7cf475644f721b9f8f2d42f35eaa2ed47eca512645cb6b55f615e2a1eb7c3a197e6e98a9f01f1ef9aa262e4fdbdb09eaea6e0ad7f10047f9273841
data/README.md CHANGED
@@ -4,7 +4,7 @@ Icodi - Deterministic Random SVG Icon Generator
4
4
  ==================================================
5
5
 
6
6
  [![Gem Version](https://badge.fury.io/rb/icodi.svg)](https://badge.fury.io/rb/icodi)
7
- [![Build Status](https://travis-ci.com/DannyBen/icodi.svg?branch=master)](https://travis-ci.com/DannyBen/icodi)
7
+ [![Build Status](https://github.com/DannyBen/icodi/workflows/Test/badge.svg)](https://github.com/DannyBen/icodi/actions?query=workflow%3ATest)
8
8
  [![Maintainability](https://api.codeclimate.com/v1/badges/0b74be3877413501c7a9/maintainability)](https://codeclimate.com/github/DannyBen/icodi/maintainability)
9
9
 
10
10
  ---
@@ -18,10 +18,12 @@ Table of Contents
18
18
  --------------------------------------------------
19
19
 
20
20
  - [Installation](#installation)
21
+ - [Demo](#demo)
21
22
  - [Examples](#examples)
22
23
  - [Usage](#usage)
23
24
  - [Options](#options)
24
25
  - [Using with Sinatra](#using-with-sinatra)
26
+ - [Contributing / Support](#contributing--support)
25
27
 
26
28
 
27
29
  Installation
@@ -31,6 +33,13 @@ Installation
31
33
 
32
34
 
33
35
 
36
+ Demo
37
+ --------------------------------------------------
38
+
39
+ Visit the [Icodi Playground] to experiment with the parameters.
40
+
41
+
42
+
34
43
  Examples
35
44
  --------------------------------------------------
36
45
 
@@ -132,9 +141,18 @@ Using with Sinatra
132
141
  --------------------------------------------------
133
142
 
134
143
  To create a Sinatra server that serves Icodi images, see the
135
- [server.rb](server.rb) example code.
144
+ [config.ru](config.ru) example code.
136
145
 
137
146
 
147
+ Contributing / Support
148
+ --------------------------------------------------
149
+
150
+ If you experience any issue, have a question or a suggestion, or if you wish
151
+ to contribute, feel free to [open an issue][issues].
152
+
153
+ ---
138
154
 
139
155
  [GitHub identicons]: https://blog.github.com/2013-08-14-identicons/
140
156
  [Victor SVG Templates]: https://github.com/DannyBen/victor#svg-templates
157
+ [Icodi Playground]: https://icodi.dannyb.co/sandbox
158
+ [issues]: https://github.com/DannyBen/icodi/issues
@@ -0,0 +1,68 @@
1
+ module IcodiCore
2
+ module Options
3
+ def default_options
4
+ {
5
+ pixels: 5,
6
+ density: 0.5,
7
+ stroke: 0.1,
8
+ background: '#fff',
9
+ color: random_color,
10
+ mirror: :x,
11
+ jitter: 0,
12
+ id: :icodi,
13
+ }
14
+ end
15
+
16
+ def background
17
+ options[:background]
18
+ end
19
+
20
+ def color
21
+ options[:color]
22
+ end
23
+
24
+ def density
25
+ options[:density]
26
+ end
27
+
28
+ def id
29
+ options[:id]
30
+ end
31
+
32
+ def jitter
33
+ options[:jitter]
34
+ end
35
+
36
+ def mirror
37
+ options[:mirror]
38
+ end
39
+
40
+ def mirror_x?
41
+ %i[x both].include? mirror
42
+ end
43
+
44
+ def mirror_y?
45
+ %i[y both].include? mirror
46
+ end
47
+
48
+ def mirror_both?
49
+ mirror == :both
50
+ end
51
+
52
+ def pixels
53
+ options[:pixels]
54
+ end
55
+
56
+ def size
57
+ @size ||= pixels * 10
58
+ end
59
+
60
+ def stroke
61
+ options[:stroke]
62
+ end
63
+
64
+ def style
65
+ @style ||= { stroke: color, stroke_width: stroke }
66
+ end
67
+ end
68
+ end
@@ -1,9 +1,5 @@
1
1
  module IcodiCore
2
2
  module Randomization
3
- def random_color
4
- "#%06x" % (random(:color).rand * 0xffffff)
5
- end
6
-
7
3
  def seed(string)
8
4
  Digest::MD5.hexdigest(string).to_i(16)
9
5
  end
@@ -16,6 +12,5 @@ module IcodiCore
16
12
  def random_sets
17
13
  @random_sets ||= {}
18
14
  end
19
-
20
15
  end
21
- end
16
+ end
data/lib/icodi.rb CHANGED
@@ -1,22 +1,27 @@
1
1
  require 'victor'
2
2
  require 'digest/md5'
3
- require 'icodi/option_handling'
3
+ require 'icodi/options'
4
4
  require 'icodi/randomization'
5
5
 
6
6
  class Icodi < Victor::SVGBase
7
- include IcodiCore::OptionHandling
7
+ include IcodiCore::Options
8
8
  include IcodiCore::Randomization
9
9
 
10
10
  attr_reader :text, :options
11
11
 
12
12
  def initialize(text = nil, opts = {})
13
- text, opts = nil, text if text.is_a? Hash
14
-
13
+ if text.is_a? Hash
14
+ opts = text
15
+ text = nil
16
+ end
17
+
18
+ svg_template = opts.delete :template
19
+
15
20
  @text = text
16
21
  @options = default_options.merge opts
17
22
 
18
- super template: template, viewBox: "0 0 #{size} #{size}", id: id
19
-
23
+ super template: svg_template, viewBox: "0 0 #{size} #{size}", id: id
24
+
20
25
  generate
21
26
  end
22
27
 
@@ -39,7 +44,7 @@ private
39
44
  element :g, clip_path: "url(##{clip_path_id})" do
40
45
  draw x, y
41
46
  end
42
- end
47
+ end
43
48
 
44
49
  def draw(x_times, y_times)
45
50
  y_times.times do |y|
@@ -47,7 +52,7 @@ private
47
52
  add_pixels x, y if random.rand < density
48
53
  end
49
54
  end
50
- end
55
+ end
51
56
 
52
57
  def add_pixels(x, y)
53
58
  x, y = add_jitter x, y
@@ -59,21 +64,27 @@ private
59
64
  end
60
65
 
61
66
  def add_jitter(x, y)
62
- return [x, y] unless jitter > 0 and random(:jitter).rand < jitter
63
-
64
- x += [0, 0.5, -0.5][random(:jitter).rand(3)] unless mirror_x? and mid? x: x
65
- y += [0, 0.5, -0.5][random(:jitter).rand(3)] unless mirror_y? and mid? y: y
67
+ if jitter.positive? && (random(:jitter).rand < jitter)
68
+ add_jitter! x, y
69
+ else
70
+ [x, y]
71
+ end
72
+ end
73
+
74
+ def add_jitter!(x, y)
75
+ x += random_jitter unless mirror_x? && mid?(x: x)
76
+ y += random_jitter unless mirror_y? && mid?(y: y)
66
77
  [x, y]
67
78
  end
68
79
 
69
80
  def draw_pixel(x, y)
70
- element :rect, x: x*10, y: y*10, width: 10, height: 10, fill: color, style: style
81
+ element :rect, x: x * 10, y: y * 10, width: 10, height: 10, fill: color, style: style
71
82
  end
72
83
 
73
84
  # Drawing Utilities
74
85
 
75
86
  def mirror?(x: nil, y: nil)
76
- if x and y
87
+ if x && y
77
88
  mirror_both? and !mid?(x: x) and !mid?(y: y)
78
89
  elsif x
79
90
  mirror_x? and !mid? x: x
@@ -83,7 +94,11 @@ private
83
94
  end
84
95
 
85
96
  def mid?(x: nil, y: nil)
86
- x ? x == pixels/2 : y ? y == pixels/2 : nil
97
+ if x
98
+ x == pixels / 2
99
+ elsif y
100
+ y == pixels / 2
101
+ end
87
102
  end
88
103
 
89
104
  def mirror_value(value)
@@ -91,6 +106,14 @@ private
91
106
  end
92
107
 
93
108
  def random_id
94
- random(:nonvisual).rand(9999999)
109
+ random(:nonvisual).rand(9_999_999)
110
+ end
111
+
112
+ def random_jitter
113
+ [0, 0.5, -0.5][random(:jitter).rand(3)]
114
+ end
115
+
116
+ def random_color
117
+ '#%06x' % (random(:color).rand * 0xffffff)
95
118
  end
96
119
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: icodi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Ben Shitrit
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-12-20 00:00:00.000000000 Z
11
+ date: 2023-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: victor
@@ -32,12 +32,15 @@ extra_rdoc_files: []
32
32
  files:
33
33
  - README.md
34
34
  - lib/icodi.rb
35
- - lib/icodi/option_handling.rb
35
+ - lib/icodi/options.rb
36
36
  - lib/icodi/randomization.rb
37
37
  homepage: https://github.com/dannyben/icodi
38
38
  licenses:
39
39
  - MIT
40
- metadata: {}
40
+ metadata:
41
+ bug_tracker_uri: https://github.com/DannyBen/icodi/issues
42
+ source_code_uri: https://github.com/DannyBen/icodi
43
+ rubygems_mfa_required: 'true'
41
44
  post_install_message:
42
45
  rdoc_options: []
43
46
  require_paths:
@@ -46,15 +49,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
46
49
  requirements:
47
50
  - - ">="
48
51
  - !ruby/object:Gem::Version
49
- version: 2.4.0
52
+ version: 2.7.0
50
53
  required_rubygems_version: !ruby/object:Gem::Requirement
51
54
  requirements:
52
55
  - - ">="
53
56
  - !ruby/object:Gem::Version
54
57
  version: '0'
55
58
  requirements: []
56
- rubyforge_project:
57
- rubygems_version: 2.7.6
59
+ rubygems_version: 3.4.7
58
60
  signing_key:
59
61
  specification_version: 4
60
62
  summary: Deterministic Random SVG Icon Generator
@@ -1,48 +0,0 @@
1
- module IcodiCore
2
- module OptionHandling
3
- def method_missing(method_name, *_args, &_block)
4
- respond_to?(method_name) ? options[method_name] : super
5
- end
6
-
7
- def respond_to?(method_name, include_private = false)
8
- options.has_key?(method_name) ? true : super
9
- end
10
-
11
- def default_options
12
- {
13
- template: :default,
14
- pixels: 5,
15
- density: 0.5,
16
- stroke: 0.1,
17
- background: '#fff',
18
- color: random_color,
19
- mirror: :x,
20
- jitter: 0,
21
- id: :icodi,
22
- }
23
- end
24
-
25
- # Derivative Properties
26
-
27
- def size
28
- @size ||= pixels * 10
29
- end
30
-
31
- def style
32
- @style ||= { stroke: color, stroke_width: stroke }
33
- end
34
-
35
- def mirror_x?
36
- [:x, :both].include? mirror
37
- end
38
-
39
- def mirror_y?
40
- [:y, :both].include? mirror
41
- end
42
-
43
- def mirror_both?
44
- mirror == :both
45
- end
46
-
47
- end
48
- end