icodi 0.0.1 → 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 +4 -4
- data/README.md +89 -3
- data/lib/icodi.rb +18 -22
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0a3f414c62dea517e5a15996bffc590270bc185afc1bcf95258ba8a081d16891
|
4
|
+
data.tar.gz: 5407c73c9d3213d87a7b1f359efb64e0bfa57c8b1e72feb2ef859480c1499d6c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 27d92abc7cceb5ca423e063877a8e154ca1cf297ea08310b42574c6e829b8b2d191f59fb11910f475647c8a8fd3428dfbbeb04530937f3475cf2e77095363a08
|
7
|
+
data.tar.gz: 2d86e71a27ae1cbee43b2834ae328d9cc7d917e978c3f8bfd874fa1718674cd4ace2783548ec7372a26e5c07fb21d65526481ce9f34130493724db7a56720f67
|
data/README.md
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+

|
2
|
+
|
1
3
|
Icodi - Deterministic Random SVG Icon Generator
|
2
4
|
==================================================
|
3
5
|
|
@@ -6,8 +8,8 @@ Icodi - Deterministic Random SVG Icon Generator
|
|
6
8
|
|
7
9
|
---
|
8
10
|
|
9
|
-
Generate repeatable random SVG icons from any string, similar to
|
10
|
-
identicons.
|
11
|
+
Generate repeatable random SVG icons from any string, similar to
|
12
|
+
[GitHub identicons].
|
11
13
|
|
12
14
|
---
|
13
15
|
|
@@ -18,7 +20,91 @@ Installation
|
|
18
20
|
|
19
21
|
|
20
22
|
|
23
|
+
Examples
|
24
|
+
--------------------------------------------------
|
25
|
+
|
26
|
+
### Grid: 5x5, Mirror: X (default options)
|
27
|
+
|
28
|
+

|
29
|
+
|
30
|
+
### Grid: 6x6, Mirror: Y
|
31
|
+
|
32
|
+

|
33
|
+
|
34
|
+
### Grid: 8x8, Mirror: X/Y, Density: 0.3
|
35
|
+
|
36
|
+

|
37
|
+
|
38
|
+
### Grid: 8x8, Mirror: X/Y, Density: 0.8
|
39
|
+
|
40
|
+

|
41
|
+
|
42
|
+
### Increasing Stroke: 0.1 - 5.0
|
43
|
+
|
44
|
+

|
45
|
+
|
46
|
+
### Increasing Density: 0.3 - 0.8
|
47
|
+
|
48
|
+

|
49
|
+
|
50
|
+
### Mirror Styles: X, Y, Both, None
|
51
|
+
|
52
|
+

|
53
|
+
|
54
|
+
|
21
55
|
Usage
|
22
56
|
--------------------------------------------------
|
23
57
|
|
24
|
-
|
58
|
+
This is the general usage pattern:
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
require 'icodi'
|
62
|
+
|
63
|
+
# initialize with optional text and options
|
64
|
+
icon = Icodi.new text, options
|
65
|
+
|
66
|
+
# get the SVG string
|
67
|
+
icon.render
|
68
|
+
|
69
|
+
# or save to SVG file
|
70
|
+
icon.save 'logo'
|
71
|
+
```
|
72
|
+
|
73
|
+
Generate a random icon with the default options, and save it to `icon.svg`:
|
74
|
+
|
75
|
+
```ruby
|
76
|
+
icon = Icodi.new
|
77
|
+
icon.save 'icon'
|
78
|
+
```
|
79
|
+
|
80
|
+
Generate persistent random icon (same input generates the same output):
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
icon = Icodi.new "any string"
|
84
|
+
icon.save 'icon'
|
85
|
+
```
|
86
|
+
|
87
|
+
Options
|
88
|
+
--------------------------------------------------
|
89
|
+
|
90
|
+
Options can be provided as the first or second argument:
|
91
|
+
|
92
|
+
```ruby
|
93
|
+
Icodi.new "any string", pixels: 8, density: 0.3
|
94
|
+
Icodi.new pixels: 8, density: 0.3, stroke: 2
|
95
|
+
```
|
96
|
+
|
97
|
+
Parameter | Default | Type | Description
|
98
|
+
------------|------------|---------|---------------------
|
99
|
+
`pixels` | `5` | Integer | Grid size.
|
100
|
+
`mirror` | `:x` | Symbol | Mirroring mode: `:x`, `:y`, `:both` or `:none`.
|
101
|
+
`color` | Deterministic Random | String | A color string for the pixels.
|
102
|
+
`density` | `0.5` | Float | A value between 0 and 1 representing the chance for a pixel to be drawn. Lower values mean less pixels.
|
103
|
+
`stroke` | `0.1` | Float | Width of the border around each pixel. Note that each pixel is a 10x10 box, so a stroke of 1 means it will take 10% of the box. Higher values generate more overlap between the pixels.
|
104
|
+
`background`| `#fff` | String | A named SVG color string (`blue`, `yellow` etc.) or RGB color (for example `#dddddd`).
|
105
|
+
`template` | `:default` | Symbol/String | SVG template to use. Can be `:default`, `:html` or a path to a file. Read more on [Victor SVG Templates].
|
106
|
+
|
107
|
+
---
|
108
|
+
|
109
|
+
[GitHub identicons]: https://blog.github.com/2013-08-14-identicons/
|
110
|
+
[Victor SVG Templates]: https://github.com/DannyBen/victor#svg-templates
|
data/lib/icodi.rb
CHANGED
@@ -8,6 +8,8 @@ class Icodi < Victor::SVGBase
|
|
8
8
|
text, options = nil, text if text.is_a? Hash
|
9
9
|
@text, @options = text, options
|
10
10
|
super template: template, viewBox: "0 0 #{size} #{size}"
|
11
|
+
|
12
|
+
first_random_hit
|
11
13
|
generate
|
12
14
|
end
|
13
15
|
|
@@ -69,42 +71,36 @@ private
|
|
69
71
|
mirror == :both
|
70
72
|
end
|
71
73
|
|
74
|
+
def first_random_hit
|
75
|
+
options[:color] ? random.rand : color
|
76
|
+
end
|
77
|
+
|
72
78
|
def generate
|
73
|
-
color # always randomize color first
|
74
79
|
element :rect, x: 0, y: 0, width: size, height: size, fill: background
|
75
80
|
half = (pixels / 2.0).round
|
76
81
|
x = mirror_x ? half : pixels
|
77
82
|
y = mirror_y ? half : pixels
|
78
83
|
|
79
|
-
draw
|
84
|
+
draw x, y
|
80
85
|
end
|
81
86
|
|
82
|
-
def draw(
|
83
|
-
|
84
|
-
|
85
|
-
if
|
86
|
-
add_pixel x, y
|
87
|
-
add_pixel pixels-1-x, y if mirror_x and x != pixels/2
|
88
|
-
add_pixel x, pixels-1-y if mirror_y and y != pixels/2
|
89
|
-
add_pixel pixels-1-x, pixels-1-y if mirror_both and x != pixels/2 and y != pixels/2
|
90
|
-
end
|
87
|
+
def draw(x_times, y_times)
|
88
|
+
y_times.times do |y|
|
89
|
+
x_times.times do |x|
|
90
|
+
add_pixels x, y if random.rand < density
|
91
91
|
end
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
95
|
-
def
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
matrix[y][x] = random.rand < density
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
matrix
|
95
|
+
def add_pixels(x, y)
|
96
|
+
draw_pixel x, y
|
97
|
+
draw_pixel pixels-1-x, y if mirror_x and x != pixels/2
|
98
|
+
draw_pixel x, pixels-1-y if mirror_y and y != pixels/2
|
99
|
+
draw_pixel pixels-1-x, pixels-1-y if mirror_both and x != pixels/2 and y != pixels/2
|
105
100
|
end
|
106
101
|
|
107
|
-
def
|
102
|
+
def draw_pixel(x, y)
|
108
103
|
element :rect, x: x*10, y: y*10, width: 10, height: 10, fill: color, style: style
|
109
104
|
end
|
105
|
+
|
110
106
|
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.0
|
4
|
+
version: 0.1.0
|
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-
|
11
|
+
date: 2018-12-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: victor
|