geo_pattern 1.4.0 → 1.6.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 +5 -5
- data/CHANGELOG.md +24 -0
- data/README.md +80 -16
- data/lib/geo_pattern/background.rb +9 -7
- data/lib/geo_pattern/background_generators/solid_generator.rb +4 -2
- data/lib/geo_pattern/color.rb +3 -1
- data/lib/geo_pattern/color_generators/base_color_generator.rb +10 -15
- data/lib/geo_pattern/color_generators/simple_generator.rb +2 -0
- data/lib/geo_pattern/color_preset.rb +7 -1
- data/lib/geo_pattern/errors.rb +2 -0
- data/lib/geo_pattern/geo_pattern_task.rb +11 -9
- data/lib/geo_pattern/helpers.rb +7 -5
- data/lib/geo_pattern/pattern.rb +6 -4
- data/lib/geo_pattern/pattern_generator.rb +14 -12
- data/lib/geo_pattern/pattern_helpers.rb +29 -11
- data/lib/geo_pattern/pattern_preset.rb +3 -1
- data/lib/geo_pattern/pattern_sieve.rb +5 -3
- data/lib/geo_pattern/pattern_store.rb +20 -18
- data/lib/geo_pattern/pattern_validator.rb +4 -2
- data/lib/geo_pattern/rake_task.rb +19 -16
- data/lib/geo_pattern/roles/comparable_metadata.rb +3 -1
- data/lib/geo_pattern/roles/named_generator.rb +3 -1
- data/lib/geo_pattern/seed.rb +2 -0
- data/lib/geo_pattern/structure.rb +9 -7
- data/lib/geo_pattern/structure_generators/base_generator.rb +17 -14
- data/lib/geo_pattern/structure_generators/chevrons_generator.rb +19 -17
- data/lib/geo_pattern/structure_generators/concentric_circles_generator.rb +19 -17
- data/lib/geo_pattern/structure_generators/diamonds_generator.rb +23 -17
- data/lib/geo_pattern/structure_generators/hexagons_generator.rb +25 -23
- data/lib/geo_pattern/structure_generators/mosaic_squares_generator.rb +35 -35
- data/lib/geo_pattern/structure_generators/nested_squares_generator.rb +23 -21
- data/lib/geo_pattern/structure_generators/octagons_generator.rb +12 -11
- data/lib/geo_pattern/structure_generators/overlapping_circles_generator.rb +13 -11
- data/lib/geo_pattern/structure_generators/overlapping_rings_generator.rb +15 -13
- data/lib/geo_pattern/structure_generators/plaid_generator.rb +18 -18
- data/lib/geo_pattern/structure_generators/plus_signs_generator.rb +24 -18
- data/lib/geo_pattern/structure_generators/sine_waves_generator.rb +17 -15
- data/lib/geo_pattern/structure_generators/squares_generator.rb +10 -9
- data/lib/geo_pattern/structure_generators/tessellation_generator.rb +36 -34
- data/lib/geo_pattern/structure_generators/triangles_generator.rb +22 -19
- data/lib/geo_pattern/structure_generators/xes_generator.rb +26 -19
- data/lib/geo_pattern/svg_image.rb +10 -8
- data/lib/geo_pattern/version.rb +3 -1
- data/lib/geo_pattern.rb +53 -51
- metadata +61 -139
- data/.gitignore +0 -18
- data/.rspec +0 -3
- data/.rubocop.yml +0 -71
- data/.simplecov +0 -25
- data/.travis.yml +0 -12
- data/Gemfile +0 -26
- data/Rakefile +0 -86
- data/fixtures/generated_patterns/chevrons.svg +0 -1
- data/fixtures/generated_patterns/concentric_circles.svg +0 -1
- data/fixtures/generated_patterns/diamonds.svg +0 -1
- data/fixtures/generated_patterns/diamonds_with_base_color.svg +0 -1
- data/fixtures/generated_patterns/diamonds_with_color.svg +0 -1
- data/fixtures/generated_patterns/hexagons.svg +0 -1
- data/fixtures/generated_patterns/mosaic_squares.svg +0 -1
- data/fixtures/generated_patterns/nested_squares.svg +0 -1
- data/fixtures/generated_patterns/octagons.svg +0 -1
- data/fixtures/generated_patterns/overlapping_circles.svg +0 -1
- data/fixtures/generated_patterns/overlapping_rings.svg +0 -1
- data/fixtures/generated_patterns/plaid.svg +0 -1
- data/fixtures/generated_patterns/plus_signs.svg +0 -1
- data/fixtures/generated_patterns/sine_waves.svg +0 -1
- data/fixtures/generated_patterns/squares.svg +0 -1
- data/fixtures/generated_patterns/tessellation.svg +0 -1
- data/fixtures/generated_patterns/triangles.svg +0 -1
- data/fixtures/generated_patterns/xes.svg +0 -1
- data/geo_pattern.gemspec +0 -29
- data/script/bootstrap +0 -30
- data/script/console +0 -8
- data/script/test +0 -21
- data/spec/background_generators/solid_generator_spec.rb +0 -50
- data/spec/background_spec.rb +0 -25
- data/spec/color_generators/base_color_generator_spec.rb +0 -31
- data/spec/color_generators/simple_generator_spec.rb +0 -12
- data/spec/color_preset_spec.rb +0 -53
- data/spec/color_spec.rb +0 -15
- data/spec/geo_pattern_spec.rb +0 -115
- data/spec/helpers_spec.rb +0 -65
- data/spec/pattern_preset_spec.rb +0 -41
- data/spec/pattern_sieve_spec.rb +0 -66
- data/spec/pattern_spec.rb +0 -72
- data/spec/pattern_store_spec.rb +0 -47
- data/spec/pattern_validator_spec.rb +0 -28
- data/spec/seed_spec.rb +0 -14
- data/spec/spec_helper.rb +0 -18
- data/spec/structure_generators/chevrons_generator_spec.rb +0 -5
- data/spec/structure_generators/concentric_circles_generator_spec.rb +0 -5
- data/spec/structure_generators/diamonds_generator_spec.rb +0 -5
- data/spec/structure_generators/hexagons_generator_spec.rb +0 -5
- data/spec/structure_generators/mosaic_squares_generator_spec.rb +0 -5
- data/spec/structure_generators/nested_squares_generator_spec.rb +0 -5
- data/spec/structure_generators/octagons_generator_spec.rb +0 -5
- data/spec/structure_generators/overlapping_circles_generator_spec.rb +0 -5
- data/spec/structure_generators/overlapping_rings_generator_spec.rb +0 -5
- data/spec/structure_generators/plaid_generator_spec.rb +0 -5
- data/spec/structure_generators/plus_signs_generator_spec.rb +0 -5
- data/spec/structure_generators/sine_waves_generator_spec.rb +0 -5
- data/spec/structure_generators/squares_generator_spec.rb +0 -5
- data/spec/structure_generators/tessellation_generator_spec.rb +0 -5
- data/spec/structure_generators/triangles_generator_spec.rb +0 -5
- data/spec/structure_generators/xes_generator_spec.rb +0 -5
- data/spec/structure_spec.rb +0 -38
- data/spec/support/aruba.rb +0 -24
- data/spec/support/helpers/fixtures.rb +0 -12
- data/spec/support/kernel.rb +0 -40
- data/spec/support/matchers/image.rb +0 -17
- data/spec/support/matchers/name.rb +0 -15
- data/spec/support/rspec.rb +0 -24
- data/spec/support/shared_examples/generator.rb +0 -46
- data/spec/support/shared_examples/pattern.rb +0 -31
- data/spec/support/shared_examples/pattern_name.rb +0 -7
- data/spec/support/shared_examples/structure.rb +0 -48
- data/spec/support/string.rb +0 -2
- data/spec/svg_spec.rb +0 -12
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 30789aa4eac2677abe68600971518bbb7156096cbe03a96621668510fcf4c98d
|
|
4
|
+
data.tar.gz: c9f14ba660f3b899f5087f393afd8092d4e9396db858f6be7d62f3d90d3bf5f0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 15da01911979383ba80390581cf9d20e36221c3dca557487727bf4d276cc3c3f789bc3be9664880eb01af283998cdf888eb93270df1af666e24301f833d94519
|
|
7
|
+
data.tar.gz: cbd53e9a6fabaa3e567d8cb5e966030196a1d57fe0393f25be55612f9189e016e173b0e9a7e2ea12d0d3fc030f7077d4006b49ab2412309d897dd93a77fab121
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 1.6.0
|
|
4
|
+
|
|
5
|
+
- Support color 2.x, whose color objects are immutable, while retaining support
|
|
6
|
+
for color 1.x and the existing SVG fixtures.
|
|
7
|
+
- Declare the base64, logger, and rake runtime dependencies so the gem and its Rake
|
|
8
|
+
integration work under Bundler on modern Ruby versions.
|
|
9
|
+
- Test Ruby 3.3, 3.4, 4.0, and Ruby head against color 1.x and 2.x in CI.
|
|
10
|
+
- Verify the built gem in CI with only its runtime dependencies installed.
|
|
11
|
+
- Publish version tags through GitHub Actions using RubyGems trusted publishing,
|
|
12
|
+
after the test and package checks pass.
|
|
13
|
+
- Remove unused ActiveSupport, documentation, and debugger dependencies from
|
|
14
|
+
the development bundle.
|
|
15
|
+
- Update coverage configuration for SimpleCov 1.3. Development tools require
|
|
16
|
+
Ruby 3.3 or newer.
|
|
17
|
+
- Package the library, README, license, and changelog without requiring Git.
|
|
18
|
+
|
|
19
|
+
The minimum Ruby version remains 2.6.
|
|
20
|
+
|
|
21
|
+
## 1.5.0 — 2023-04-05
|
|
22
|
+
|
|
23
|
+
- Fix Ruby 3 compatibility.
|
|
24
|
+
- Require Ruby 2.6 or newer.
|
data/README.md
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
### This project is largely unmaintained now.
|
|
2
|
+
|
|
3
|
+
#### I'll happily accept PRs to keep things in working order, but I no longer plan to make updates.
|
|
4
|
+
|
|
5
|
+
----
|
|
6
|
+
|
|
7
|
+
[](http://rubygems.org/gems/geo_pattern)
|
|
8
|
+

|
|
9
|
+
[](http://rubygems.org/gems/geo_pattern)
|
|
10
|
+
[](https://github.com/testdouble/standard)
|
|
4
11
|
|
|
5
12
|
# GeoPattern
|
|
6
13
|
|
|
@@ -14,7 +21,7 @@ You can use the generated pattern as the `background-image` for a container.
|
|
|
14
21
|
Using the `base64` representation of the pattern still results in SVG
|
|
15
22
|
rendering, so it looks great on retina displays.
|
|
16
23
|
|
|
17
|
-
See the [GitHub Guides](
|
|
24
|
+
See the [GitHub Guides](https://guides.github.com/) site and the [Explore section
|
|
18
25
|
of GitHub](https://github.com/explore) are examples of this library in action.
|
|
19
26
|
Brandon Mills has put together an awesome [live preview
|
|
20
27
|
page](http://btmills.github.io/geopattern/geopattern.html) that's built on his
|
|
@@ -22,6 +29,8 @@ Javascript port.
|
|
|
22
29
|
|
|
23
30
|
## Installation
|
|
24
31
|
|
|
32
|
+
Ruby 2.6 or greater is required. GeoPattern supports both color 1.x and 2.x.
|
|
33
|
+
|
|
25
34
|
Add this line to your application's Gemfile:
|
|
26
35
|
|
|
27
36
|
gem 'geo_pattern'
|
|
@@ -156,10 +165,6 @@ are deprecated in favor of symbol references (e.g. `:overlapping_circles`).*
|
|
|
156
165
|
|
|
157
166
|

|
|
158
167
|
|
|
159
|
-
### GeoPattern::ChevronPattern
|
|
160
|
-
|
|
161
|
-

|
|
162
|
-
|
|
163
168
|
|
|
164
169
|
## Inspection of pattern
|
|
165
170
|
|
|
@@ -215,21 +220,59 @@ GeoPattern::GeoPatternTask.new(
|
|
|
215
220
|
|
|
216
221
|
## Developing
|
|
217
222
|
|
|
223
|
+
Use Ruby 3.3 or newer for development and install dependencies with `bundle install`.
|
|
224
|
+
|
|
218
225
|
### Generate Fixtures
|
|
219
226
|
|
|
220
|
-
```
|
|
221
|
-
rake fixtures:generate
|
|
227
|
+
```sh
|
|
228
|
+
bundle exec rake fixtures:generate
|
|
222
229
|
```
|
|
223
230
|
|
|
224
231
|
### Run tests
|
|
225
232
|
|
|
226
|
-
```
|
|
227
|
-
rake test
|
|
233
|
+
```sh
|
|
234
|
+
bundle exec rake test
|
|
228
235
|
```
|
|
229
236
|
|
|
237
|
+
### Releasing
|
|
238
|
+
|
|
239
|
+
See [CHANGELOG.md](CHANGELOG.md) for release notes. To prepare a release, update
|
|
240
|
+
`lib/geo_pattern/version.rb` and the changelog, then run:
|
|
241
|
+
|
|
242
|
+
```sh
|
|
243
|
+
bundle install
|
|
244
|
+
bundle exec rake test
|
|
245
|
+
bundle exec rake gem:build
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
Releases are published by [the release workflow](.github/workflows/release.yml)
|
|
249
|
+
when a version tag is pushed. The workflow runs the test and package checks,
|
|
250
|
+
verifies that the tag matches the gem version, and publishes to RubyGems.org.
|
|
251
|
+
|
|
252
|
+
Before the first automated release, a gem owner must configure
|
|
253
|
+
[RubyGems trusted publishing](https://guides.rubygems.org/trusted-publishing/)
|
|
254
|
+
for `geo_pattern` with these values:
|
|
255
|
+
|
|
256
|
+
- Repository owner: `jasonlong`
|
|
257
|
+
- Repository name: `geo_pattern`
|
|
258
|
+
- Workflow filename: `release.yml`
|
|
259
|
+
- Environment: `release`
|
|
260
|
+
|
|
261
|
+
Create the matching `release` environment in the repository's GitHub settings.
|
|
262
|
+
The workflow uses short-lived credentials; no RubyGems API key secret is needed.
|
|
263
|
+
|
|
264
|
+
Commit and push the release changes, then tag that commit and push the tag:
|
|
265
|
+
|
|
266
|
+
```sh
|
|
267
|
+
git tag v1.6.0
|
|
268
|
+
git push origin v1.6.0
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
Use the version from `lib/geo_pattern/version.rb` for subsequent releases.
|
|
272
|
+
|
|
230
273
|
## Contributing
|
|
231
274
|
|
|
232
|
-
1. Fork it (
|
|
275
|
+
1. Fork it ( https://github.com/jasonlong/geo_pattern/fork )
|
|
233
276
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
234
277
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
235
278
|
4. Push to the branch (`git push origin my-new-feature`)
|
|
@@ -244,19 +287,40 @@ examples of the test suite.
|
|
|
244
287
|
RSPEC_PROFILE=1 bundle exec rspec
|
|
245
288
|
```
|
|
246
289
|
|
|
247
|
-
## Ports
|
|
290
|
+
## Ports & related projects
|
|
248
291
|
|
|
249
292
|
JavaScript port by Brandon Mills:
|
|
250
|
-
https://github.com/btmills/
|
|
293
|
+
https://github.com/btmills/geopattern
|
|
294
|
+
|
|
295
|
+
TypeScript port by MooYeol Lee:
|
|
296
|
+
https://github.com/mooyoul/geo-pattern
|
|
251
297
|
|
|
252
298
|
Python port by Bryan Veloso:
|
|
253
299
|
https://github.com/bryanveloso/geopatterns
|
|
254
300
|
|
|
301
|
+
Elixir port by Anne Johnson:
|
|
302
|
+
https://github.com/annejohnson/geo_pattern
|
|
303
|
+
|
|
255
304
|
PHP port by Anand Capur:
|
|
256
305
|
https://github.com/redeyeventures/geopattern-php
|
|
257
306
|
|
|
258
307
|
Go port by Pravendra Singh:
|
|
259
|
-
https://github.com/pravj/
|
|
308
|
+
https://github.com/pravj/geopattern
|
|
260
309
|
|
|
261
310
|
CoffeeScript port by Aleks (muchweb):
|
|
262
311
|
https://github.com/muchweb/geo-pattern-coffee
|
|
312
|
+
|
|
313
|
+
Cocoa port by Matt Faluotico:
|
|
314
|
+
https://github.com/mattfxyz/GeoPattern-Cocoa
|
|
315
|
+
|
|
316
|
+
Middleman extension by @maxmeyer:
|
|
317
|
+
https://github.com/fedux-org/middleman-geo_pattern
|
|
318
|
+
|
|
319
|
+
Dart(Flutter) port by @suyash:
|
|
320
|
+
https://github.com/suyash/geopattern
|
|
321
|
+
|
|
322
|
+
Lua port by Ivan Azoyan:
|
|
323
|
+
https://github.com/azoyan/geopattern
|
|
324
|
+
|
|
325
|
+
Java port by Jason Selzer:
|
|
326
|
+
https://github.com/jselzer/geopattern
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module GeoPattern
|
|
2
4
|
class Background
|
|
3
5
|
include Roles::ComparableMetadata
|
|
@@ -9,15 +11,15 @@ module GeoPattern
|
|
|
9
11
|
def_delegators :@preset, :base_color
|
|
10
12
|
|
|
11
13
|
def initialize(options)
|
|
12
|
-
@image
|
|
13
|
-
@preset
|
|
14
|
-
@color
|
|
14
|
+
@image = options[:image]
|
|
15
|
+
@preset = options[:preset]
|
|
16
|
+
@color = options[:color]
|
|
15
17
|
@generator = options[:generator]
|
|
16
18
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
raise ArgumentError, "Argument color is missing" if @color.nil?
|
|
20
|
+
raise ArgumentError, "Argument image is missing" if @image.nil?
|
|
21
|
+
raise ArgumentError, "Argument preset is missing" if @preset.nil?
|
|
22
|
+
raise ArgumentError, "Argument generator is missing" if @generator.nil?
|
|
21
23
|
end
|
|
22
24
|
|
|
23
25
|
def_comparators :base_color, :color
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module GeoPattern
|
|
2
4
|
# Generating backgrounds
|
|
3
5
|
module BackgroundGenerators
|
|
@@ -19,7 +21,7 @@ module GeoPattern
|
|
|
19
21
|
# @param [ColorPreset] preset
|
|
20
22
|
# A preset of values which are used during generating the background
|
|
21
23
|
def initialize(seed, preset)
|
|
22
|
-
@color
|
|
24
|
+
@color = color_for(seed, preset)
|
|
23
25
|
@preset = preset
|
|
24
26
|
end
|
|
25
27
|
|
|
@@ -37,7 +39,7 @@ module GeoPattern
|
|
|
37
39
|
|
|
38
40
|
def generate_background
|
|
39
41
|
svg = SvgImage.new
|
|
40
|
-
svg.rect(0, 0,
|
|
42
|
+
svg.rect(0, 0, "100%", "100%", "fill" => color.to_svg)
|
|
41
43
|
|
|
42
44
|
svg
|
|
43
45
|
end
|
data/lib/geo_pattern/color.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module GeoPattern
|
|
2
4
|
class Color
|
|
3
5
|
private
|
|
@@ -15,7 +17,7 @@ module GeoPattern
|
|
|
15
17
|
g = (color.g * 255).round
|
|
16
18
|
b = (color.b * 255).round
|
|
17
19
|
|
|
18
|
-
format(
|
|
20
|
+
format("rgb(%<r>d, %<g>d, %<b>d)", r: r, g: g, b: b)
|
|
19
21
|
end
|
|
20
22
|
|
|
21
23
|
def to_html
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module GeoPattern
|
|
2
4
|
# Color generators
|
|
3
5
|
module ColorGenerators
|
|
@@ -14,8 +16,8 @@ module GeoPattern
|
|
|
14
16
|
# @param [String] color
|
|
15
17
|
# HTML color string, #0a0a0a
|
|
16
18
|
def initialize(color, seed, creator = Color)
|
|
17
|
-
@color
|
|
18
|
-
@seed
|
|
19
|
+
@color = color
|
|
20
|
+
@seed = seed
|
|
19
21
|
@creator = creator
|
|
20
22
|
end
|
|
21
23
|
|
|
@@ -27,23 +29,16 @@ module GeoPattern
|
|
|
27
29
|
private
|
|
28
30
|
|
|
29
31
|
def transform(color, seed)
|
|
30
|
-
hue_offset
|
|
31
|
-
sat_offset
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
if (sat_offset % 2 == 0)
|
|
36
|
-
new_color.saturation = new_color.saturation + sat_offset
|
|
37
|
-
else
|
|
38
|
-
new_color.saturation = new_color.saturation - sat_offset
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
new_color.html
|
|
32
|
+
hue_offset = map(seed.to_i(14, 3), 0, 4095, 0, 359)
|
|
33
|
+
sat_offset = seed.to_i(17, 1)
|
|
34
|
+
|
|
35
|
+
PatternHelpers.offset_color(color, hue_offset, sat_offset).html
|
|
42
36
|
end
|
|
43
37
|
|
|
44
38
|
# Ruby implementation of Processing's map function
|
|
45
39
|
# http://processing.org/reference/map_.html
|
|
46
|
-
|
|
40
|
+
# v for value, d for desired
|
|
41
|
+
def map(value, v_min, v_max, d_min, d_max)
|
|
47
42
|
v_value = value.to_f # so it returns float
|
|
48
43
|
|
|
49
44
|
v_range = v_max - v_min
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# rubocop:disable Lint/DuplicateMethods
|
|
4
|
+
|
|
1
5
|
module GeoPattern
|
|
2
6
|
class ColorPreset
|
|
3
7
|
attr_accessor :color, :base_color, :mode
|
|
4
8
|
|
|
5
9
|
def initialize(color: nil, base_color: nil)
|
|
6
|
-
@color
|
|
10
|
+
@color = color
|
|
7
11
|
@base_color = base_color
|
|
8
12
|
end
|
|
9
13
|
|
|
@@ -24,3 +28,5 @@ module GeoPattern
|
|
|
24
28
|
end
|
|
25
29
|
end
|
|
26
30
|
end
|
|
31
|
+
|
|
32
|
+
# rubocop:enable Lint/DuplicateMethods
|
data/lib/geo_pattern/errors.rb
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "geo_pattern"
|
|
4
|
+
require "geo_pattern/rake_task"
|
|
3
5
|
|
|
4
6
|
module GeoPattern
|
|
5
7
|
# GeoPatternTask
|
|
@@ -27,9 +29,9 @@ module GeoPattern
|
|
|
27
29
|
def initialize(opts = {})
|
|
28
30
|
super
|
|
29
31
|
|
|
30
|
-
|
|
32
|
+
raise ArgumentError, :data if @options[:data].nil?
|
|
31
33
|
|
|
32
|
-
@data
|
|
34
|
+
@data = @options[:data]
|
|
33
35
|
@allowed_patterns = @options[:allowed_patterns]
|
|
34
36
|
end
|
|
35
37
|
|
|
@@ -37,15 +39,15 @@ module GeoPattern
|
|
|
37
39
|
def run_task(_verbose)
|
|
38
40
|
data.each do |path, string|
|
|
39
41
|
opts = {}
|
|
40
|
-
path
|
|
42
|
+
path = File.expand_path(path)
|
|
41
43
|
|
|
42
44
|
if string.is_a?(Hash)
|
|
43
|
-
input
|
|
44
|
-
opts[:patterns]
|
|
45
|
-
opts[:color]
|
|
45
|
+
input = string[:input]
|
|
46
|
+
opts[:patterns] = string[:patterns] if string.key? :patterns
|
|
47
|
+
opts[:color] = string[:color] if string.key? :color
|
|
46
48
|
opts[:base_color] = string[:base_color] if string.key? :base_color
|
|
47
49
|
else
|
|
48
|
-
|
|
50
|
+
raise "Invalid data structure for Rake Task"
|
|
49
51
|
end
|
|
50
52
|
|
|
51
53
|
pattern = GeoPattern.generate(input, opts)
|
data/lib/geo_pattern/helpers.rb
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module GeoPattern
|
|
2
4
|
module Helpers
|
|
3
5
|
def require_files_matching_pattern(pattern)
|
|
4
|
-
Dir.glob(pattern).each { |f| require_relative f }
|
|
6
|
+
Dir.glob(pattern).sort.each { |f| require_relative f }
|
|
5
7
|
end
|
|
6
8
|
|
|
7
9
|
# Makes an underscored, lowercase form from the expression in the string.
|
|
@@ -10,9 +12,9 @@ module GeoPattern
|
|
|
10
12
|
# It's MIT-Licensed
|
|
11
13
|
#
|
|
12
14
|
def underscore(camel_cased_word)
|
|
13
|
-
return camel_cased_word unless
|
|
15
|
+
return camel_cased_word unless /[A-Z-]/.match?(camel_cased_word)
|
|
14
16
|
|
|
15
|
-
word = camel_cased_word.to_s
|
|
17
|
+
word = camel_cased_word.to_s.dup
|
|
16
18
|
|
|
17
19
|
word.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2')
|
|
18
20
|
word.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
|
|
@@ -38,8 +40,8 @@ module GeoPattern
|
|
|
38
40
|
def demodulize(path)
|
|
39
41
|
path = path.to_s
|
|
40
42
|
|
|
41
|
-
if i = path.rindex(
|
|
42
|
-
path[(i + 2)
|
|
43
|
+
if (i = path.rindex("::"))
|
|
44
|
+
path[(i + 2)..]
|
|
43
45
|
else
|
|
44
46
|
path
|
|
45
47
|
end
|
data/lib/geo_pattern/pattern.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module GeoPattern
|
|
2
4
|
class Pattern
|
|
3
5
|
private
|
|
@@ -48,7 +50,7 @@ module GeoPattern
|
|
|
48
50
|
# @see #to_data_uri
|
|
49
51
|
# @deprecated
|
|
50
52
|
def uri_image
|
|
51
|
-
|
|
53
|
+
warn 'Using "#uri_image" is deprecated as of 1.3.1. Please use "#to_data_uri" instead.'
|
|
52
54
|
|
|
53
55
|
to_data_uri
|
|
54
56
|
end
|
|
@@ -56,7 +58,7 @@ module GeoPattern
|
|
|
56
58
|
# @see #to_svg
|
|
57
59
|
# @deprecated
|
|
58
60
|
def svg_string
|
|
59
|
-
|
|
61
|
+
warn 'Using "#svg_string" is deprecated as of 1.3.1. Please use "#to_svg" instead.'
|
|
60
62
|
|
|
61
63
|
to_svg
|
|
62
64
|
end
|
|
@@ -64,7 +66,7 @@ module GeoPattern
|
|
|
64
66
|
# @see #to_base64
|
|
65
67
|
# @deprecated
|
|
66
68
|
def base64_string
|
|
67
|
-
|
|
69
|
+
warn 'Using "#base64_string" is deprecated as of 1.3.1. Please use "#to_base64" instead.'
|
|
68
70
|
|
|
69
71
|
to_base64
|
|
70
72
|
end
|
|
@@ -73,7 +75,7 @@ module GeoPattern
|
|
|
73
75
|
|
|
74
76
|
def image
|
|
75
77
|
svg_image.height = height
|
|
76
|
-
svg_image.width
|
|
78
|
+
svg_image.width = width
|
|
77
79
|
|
|
78
80
|
svg_image << background.image if background
|
|
79
81
|
svg_image << structure.image if structure
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module GeoPattern
|
|
2
4
|
class PatternGenerator
|
|
3
5
|
private
|
|
@@ -7,37 +9,37 @@ module GeoPattern
|
|
|
7
9
|
public
|
|
8
10
|
|
|
9
11
|
def initialize(string, generator: nil, patterns: nil, base_color: nil, color: nil)
|
|
10
|
-
|
|
12
|
+
warn "Using generator key is deprecated as of 1.3.1" if generator
|
|
11
13
|
|
|
12
14
|
requested_patterns = (Array(generator) | Array(patterns)).flatten.compact
|
|
13
15
|
|
|
14
16
|
pattern_preset = PatternPreset.new(
|
|
15
|
-
fill_color_dark:
|
|
16
|
-
fill_color_light:
|
|
17
|
-
stroke_color:
|
|
17
|
+
fill_color_dark: "#222",
|
|
18
|
+
fill_color_light: "#ddd",
|
|
19
|
+
stroke_color: "#000",
|
|
18
20
|
stroke_opacity: 0.02,
|
|
19
21
|
opacity_min: 0.02,
|
|
20
22
|
opacity_max: 0.15
|
|
21
23
|
)
|
|
22
24
|
|
|
23
25
|
color_preset = ColorPreset.new(
|
|
24
|
-
base_color:
|
|
26
|
+
base_color: "#933c3c"
|
|
25
27
|
)
|
|
26
|
-
color_preset.color
|
|
28
|
+
color_preset.color = color if color
|
|
27
29
|
color_preset.base_color = base_color if base_color
|
|
28
30
|
|
|
29
31
|
seed = Seed.new(string)
|
|
30
32
|
|
|
31
|
-
pattern_validator
|
|
33
|
+
pattern_validator = PatternValidator.new
|
|
32
34
|
pattern_validator.validate(requested_patterns)
|
|
33
35
|
|
|
34
|
-
pattern_sieve
|
|
36
|
+
pattern_sieve = PatternSieve.new(requested_patterns, seed)
|
|
35
37
|
|
|
36
38
|
@background_generator = BackgroundGenerators::SolidGenerator.new(seed, color_preset)
|
|
37
|
-
@structure_generator
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
@structure_generator = begin
|
|
40
|
+
generator_klass = pattern_sieve.fetch
|
|
41
|
+
generator_klass.new(seed, pattern_preset)
|
|
42
|
+
end
|
|
41
43
|
end
|
|
42
44
|
|
|
43
45
|
def generate
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module GeoPattern
|
|
2
4
|
module PatternHelpers
|
|
3
5
|
def hex_val(hash, index, length)
|
|
@@ -6,7 +8,8 @@ module GeoPattern
|
|
|
6
8
|
|
|
7
9
|
# Ruby implementation of Processing's map function
|
|
8
10
|
# http://processing.org/reference/map_.html
|
|
9
|
-
|
|
11
|
+
# v for value, d for desired
|
|
12
|
+
def map(value, v_min, v_max, d_min, d_max)
|
|
10
13
|
v_value = value.to_f # so it returns float
|
|
11
14
|
|
|
12
15
|
v_range = v_max - v_min
|
|
@@ -19,18 +22,33 @@ module GeoPattern
|
|
|
19
22
|
end
|
|
20
23
|
|
|
21
24
|
def html_to_rgb_for_string(seed, base_color)
|
|
22
|
-
hue_offset
|
|
23
|
-
sat_offset
|
|
24
|
-
|
|
25
|
-
base_color
|
|
25
|
+
hue_offset = map(seed.to_i(14, 3), 0, 4095, 0, 359)
|
|
26
|
+
sat_offset = seed.to_i(17, 1)
|
|
27
|
+
|
|
28
|
+
generate_rgb_string(offset_color(base_color, hue_offset, sat_offset))
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Rotates the hue and shifts the saturation of an HTML color, returning a
|
|
32
|
+
# Color::RGB. Color objects are immutable as of color 2.0, so this builds a
|
|
33
|
+
# new color instead of mutating one in place.
|
|
34
|
+
def offset_color(html_color, hue_offset, sat_offset)
|
|
35
|
+
hsl = ::Color::RGB.from_html(html_color).to_hsl
|
|
36
|
+
|
|
37
|
+
hue = (hsl.hue - hue_offset) / 360.0
|
|
38
|
+
hue += 1.0 if hue < 0.0
|
|
39
|
+
hue -= 1.0 if hue > 1.0
|
|
26
40
|
|
|
27
|
-
if
|
|
28
|
-
|
|
41
|
+
saturation = if sat_offset % 2 == 0
|
|
42
|
+
hsl.saturation + sat_offset
|
|
29
43
|
else
|
|
30
|
-
|
|
44
|
+
hsl.saturation - sat_offset
|
|
31
45
|
end
|
|
32
46
|
|
|
33
|
-
|
|
47
|
+
::Color::HSL.from_fraction(
|
|
48
|
+
hue.clamp(0.0, 1.0),
|
|
49
|
+
(saturation / 100.0).clamp(0.0, 1.0),
|
|
50
|
+
hsl.l
|
|
51
|
+
).to_rgb
|
|
34
52
|
end
|
|
35
53
|
|
|
36
54
|
def generate_rgb_string(rgb)
|
|
@@ -38,9 +56,9 @@ module GeoPattern
|
|
|
38
56
|
g = (rgb.g * 255).round
|
|
39
57
|
b = (rgb.b * 255).round
|
|
40
58
|
|
|
41
|
-
format(
|
|
59
|
+
format("rgb(%<r>d, %<g>d, %<b>d)", r: r, g: g, b: b)
|
|
42
60
|
end
|
|
43
61
|
|
|
44
|
-
module_function :hex_val, :map, :html_to_rgb, :html_to_rgb_for_string, :generate_rgb_string
|
|
62
|
+
module_function :hex_val, :map, :html_to_rgb, :html_to_rgb_for_string, :offset_color, :generate_rgb_string
|
|
45
63
|
end
|
|
46
64
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module GeoPattern
|
|
2
4
|
class PatternPreset
|
|
3
5
|
private
|
|
@@ -10,7 +12,7 @@ module GeoPattern
|
|
|
10
12
|
@options = options
|
|
11
13
|
end
|
|
12
14
|
|
|
13
|
-
[
|
|
15
|
+
%i[fill_color_dark fill_color_light stroke_color stroke_opacity opacity_min opacity_max].each do |m|
|
|
14
16
|
define_method m do
|
|
15
17
|
options[m]
|
|
16
18
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module GeoPattern
|
|
2
4
|
class PatternSieve
|
|
3
5
|
private
|
|
@@ -8,11 +10,11 @@ module GeoPattern
|
|
|
8
10
|
|
|
9
11
|
def initialize(requested_patterns, seed, pattern_store = PatternStore.new)
|
|
10
12
|
@requested_patterns = requested_patterns
|
|
11
|
-
@seed
|
|
12
|
-
@pattern_store
|
|
13
|
+
@seed = seed
|
|
14
|
+
@pattern_store = pattern_store
|
|
13
15
|
|
|
14
16
|
@available_patterns = determine_available_patterns
|
|
15
|
-
@index
|
|
17
|
+
@index = determine_index
|
|
16
18
|
end
|
|
17
19
|
|
|
18
20
|
def fetch
|