class ShatteredMachine::ProgressivePixelSorter

Call the pixel sorter multiple time in steps for given png image(s)

Public Class Methods

new(io, options) click to toggle source

@param io [ShatteredMachine::Io] Io containing paths for images to glitch @param options [Hash] options for the pixel sorting algorithm

# File lib/shattered_machine/progressive_pixel_sorter.rb, line 9
def initialize(io, options)
  @io = io
  @options = options
  @images_count = @io.png_images.count
  @steps = define_steps
end

Public Instance Methods

call() click to toggle source
# File lib/shattered_machine/progressive_pixel_sorter.rb, line 16
def call
  @io.png_images.sort_by { |path| [path.input[/\d+/].to_i, path.input] }.each_with_index do |item, index|
    PixelSorter.new(sorter_options(index)).call(item.input, item.output)
  end
end

Private Instance Methods

define_new_max_limit(index) click to toggle source
# File lib/shattered_machine/progressive_pixel_sorter.rb, line 58
def define_new_max_limit(index)
  if @options[:detection_max].to_f > @options[:detection_max_two].to_f
    (@options[:detection_max].to_f - (index * @steps[:max]))
  else
    (@options[:detection_max].to_f + (index * @steps[:max]))
  end
end
define_new_min_limit(index) click to toggle source
# File lib/shattered_machine/progressive_pixel_sorter.rb, line 50
def define_new_min_limit(index)
  if @options[:detection_min].to_f > @options[:detection_min_two].to_f
    (@options[:detection_min].to_f - (index * @steps[:min]))
  else
    (@options[:detection_min].to_f + (index * @steps[:min]))
  end
end
define_steps() click to toggle source
# File lib/shattered_machine/progressive_pixel_sorter.rb, line 34
def define_steps
  { min: min_step, max: max_step }
end
max_step() click to toggle source
# File lib/shattered_machine/progressive_pixel_sorter.rb, line 42
def max_step
  positive_subtraction(@options[:detection_max].to_f, @options[:detection_max_two].to_f) / (@images_count - 1)
end
min_step() click to toggle source
# File lib/shattered_machine/progressive_pixel_sorter.rb, line 38
def min_step
  positive_subtraction(@options[:detection_min].to_f, @options[:detection_min_two].to_f) / (@images_count - 1)
end
positive_subtraction(value1, value2) click to toggle source
# File lib/shattered_machine/progressive_pixel_sorter.rb, line 46
def positive_subtraction(value1, value2)
  value1 > value2 ? value1 - value2 : value2 - value1
end
sorter_options(index) click to toggle source
# File lib/shattered_machine/progressive_pixel_sorter.rb, line 24
def sorter_options(index)
  return @options unless @options[:smart_sorting]

  step_options = @options.clone
  step_options[:multiple_ranges] = false
  step_options[:detection_min] = (define_new_min_limit(index)).round.to_s
  step_options[:detection_max] = (define_new_max_limit(index)).round.to_s
  step_options
end