Class: GeoPattern::PatternGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/geo_pattern/pattern_generator.rb

Instance Method Summary collapse

Constructor Details

#initialize(string, generator: nil, patterns: nil, base_color: nil, color: nil) ⇒ PatternGenerator

Returns a new instance of PatternGenerator


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/geo_pattern/pattern_generator.rb', line 9

def initialize(string, generator: nil, patterns: nil, base_color: nil, color: nil)
  $stderr.puts 'Using generator key is deprecated as of 1.3.1' if generator

  requested_patterns = (Array(generator) | Array(patterns)).flatten.compact

  pattern_preset = PatternPreset.new(
    fill_color_dark: '#222',
    fill_color_light: '#ddd',
    stroke_color: '#000',
    stroke_opacity: 0.02,
    opacity_min: 0.02,
    opacity_max: 0.15
  )

  color_preset = ColorPreset.new(
    base_color: '#933c3c'
  )
  color_preset.color      = color if color
  color_preset.base_color = base_color if base_color

  seed = Seed.new(string)

  pattern_validator = PatternValidator.new
  pattern_validator.validate(requested_patterns)

  pattern_sieve = PatternSieve.new(requested_patterns, seed)

  @background_generator = BackgroundGenerators::SolidGenerator.new(seed, color_preset)
  @structure_generator  = begin
                            generator_klass = pattern_sieve.fetch
                            generator_klass.new(seed, pattern_preset)
                          end
end

Instance Method Details

#generateObject


43
44
45
46
47
48
49
50
# File 'lib/geo_pattern/pattern_generator.rb', line 43

def generate
  pattern = Pattern.new

  pattern.generate_me background_generator
  pattern.generate_me structure_generator

  pattern
end