Class: FoggyMirror::Processor
- Inherits:
-
Object
- Object
- FoggyMirror::Processor
- Defined in:
- lib/foggy-mirror/processor.rb
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#image_path ⇒ Object
readonly
Returns the value of attribute image_path.
-
#overlap ⇒ Object
readonly
Returns the value of attribute overlap.
-
#random ⇒ Object
readonly
Returns the value of attribute random.
-
#random_offset ⇒ Object
readonly
Returns the value of attribute random_offset.
-
#resolution ⇒ Object
readonly
Returns the value of attribute resolution.
Instance Method Summary collapse
- #base_color ⇒ Object
- #blobs ⇒ Object
- #color_samples ⇒ Object
- #data_uri ⇒ Object
-
#initialize(image_path, resolution: DEFAULT_RESOLUTION, overlap: 0.5, distribution: nil, random_offset: 0.5, random: Random.new, adapter: default_adapter, adapter_options: {}) ⇒ Processor
constructor
A new instance of Processor.
- #to_css(hash: false) ⇒ Object
- #to_svg(strategy: nil) ⇒ Object
Constructor Details
#initialize(image_path, resolution: DEFAULT_RESOLUTION, overlap: 0.5, distribution: nil, random_offset: 0.5, random: Random.new, adapter: default_adapter, adapter_options: {}) ⇒ Processor
Returns a new instance of Processor.
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/foggy-mirror/processor.rb', line 7 def initialize(image_path, resolution: DEFAULT_RESOLUTION, overlap: 0.5, distribution: nil, random_offset: 0.5, random: Random.new, adapter: default_adapter, adapter_options: {}) @image_path = image_path @resolution = resolution @overlap = overlap @distribution = distribution @random_offset = random_offset @random = random @adapter = resolve_adapter(adapter).new(image_path, **) end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
5 6 7 |
# File 'lib/foggy-mirror/processor.rb', line 5 def adapter @adapter end |
#image_path ⇒ Object (readonly)
Returns the value of attribute image_path.
5 6 7 |
# File 'lib/foggy-mirror/processor.rb', line 5 def image_path @image_path end |
#overlap ⇒ Object (readonly)
Returns the value of attribute overlap.
5 6 7 |
# File 'lib/foggy-mirror/processor.rb', line 5 def overlap @overlap end |
#random ⇒ Object (readonly)
Returns the value of attribute random.
5 6 7 |
# File 'lib/foggy-mirror/processor.rb', line 5 def random @random end |
#random_offset ⇒ Object (readonly)
Returns the value of attribute random_offset.
5 6 7 |
# File 'lib/foggy-mirror/processor.rb', line 5 def random_offset @random_offset end |
#resolution ⇒ Object (readonly)
Returns the value of attribute resolution.
5 6 7 |
# File 'lib/foggy-mirror/processor.rb', line 5 def resolution @resolution end |
Instance Method Details
#base_color ⇒ Object
19 20 21 |
# File 'lib/foggy-mirror/processor.rb', line 19 def base_color @base_color ||= Color.new(adapter.dominant_color) end |
#blobs ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/foggy-mirror/processor.rb', line 31 def blobs samples = color_samples increment = 1.0 / (resolution - 1) blobs = resolution.times.with_object([]) do |y, blobs| resolution.times do |x| xp = x * increment + increment * random_offset * (random.rand - 0.5) yp = y * increment + increment * random_offset * (random.rand - 0.5) r = increment * (1 + overlap) color = samples[y * resolution + x] blobs << Blob.new(x: xp, y: yp, r: r, color: color) end end case @distribution.to_s.downcase when 'shuffle' blobs.shuffle(random: random) when 'spiral_in' spiral_in(blobs) when 'spiral_out' spiral_in(blobs).reverse when 'scan_reverse' blobs.reverse when 'brightness' blobs.sort_by { |b| b.color.brightness } when 'brightness_reverse' blobs.sort_by { |b| 255 - b.color.brightness } else blobs end end |
#color_samples ⇒ Object
69 70 71 |
# File 'lib/foggy-mirror/processor.rb', line 69 def color_samples @color_samples ||= adapter.color_samples(resolution) end |
#data_uri ⇒ Object
65 66 67 |
# File 'lib/foggy-mirror/processor.rb', line 65 def data_uri @data_uri ||= adapter.data_uri(resolution) end |