class Lolcommits::Plugin::Glitch
Constants
- COMPOSITE_OPERATORS
- DEFAULT_GLITCH_CHANCE
- DEFAULT_GLITCH_LEVEL
Public Instance Methods
default_options()
click to toggle source
# File lib/lolcommits/plugin/glitch.rb, line 52 def default_options { glitch_level: DEFAULT_GLITCH_LEVEL, glitch_probability: DEFAULT_GLITCH_CHANCE, } end
run_post_capture()
click to toggle source
# File lib/lolcommits/plugin/glitch.rb, line 39 def run_post_capture images = Magick::Image.read(runner.lolcommit_path) glitch_image = image = images.first wax_poetic if rand(100) < config_option(:glitch_probability) debug "Glitching #{width(image)} x #{height(image)} #{config_option(:glitch_level)} times" glitch_image = glitch_image(image) end glitch_image.write runner.lolcommit_path end
valid_configuration?()
click to toggle source
# File lib/lolcommits/plugin/glitch.rb, line 59 def valid_configuration? !@configuration.nil? && !@configuration[:glitch_level].nil? end
Private Instance Methods
debug_glitch_iteration(args)
click to toggle source
# File lib/lolcommits/plugin/glitch.rb, line 89 def debug_glitch_iteration(args) debug "…Glitching… with #{"%-#{COMPOSITE_OPERATORS.map(&:to_s).map(&:length).max}s" % args[3]} @ #{args[1..2]}" end
glitch_args_for(image)
click to toggle source
dont memoize!
# File lib/lolcommits/plugin/glitch.rb, line 94 def glitch_args_for(image) [ image, glitch_at_x(image), glitch_at_y(image), COMPOSITE_OPERATORS.sample, ] end
glitch_at_x(image)
click to toggle source
dont memoize!
# File lib/lolcommits/plugin/glitch.rb, line 104 def glitch_at_x(image) rand(0...width(image)) * [-1, 1].sample end
glitch_at_y(image)
click to toggle source
dont memoize!
# File lib/lolcommits/plugin/glitch.rb, line 109 def glitch_at_y(image) rand(0...height(image)) * [-1, 1].sample end
glitch_image(image)
click to toggle source
# File lib/lolcommits/plugin/glitch.rb, line 80 def glitch_image(image) image.dup.tap do |glitch_image| config_option(:glitch_level).times do debug_glitch_iteration glitch_args = glitch_args_for(image) glitch_image.composite!(*glitch_args) end end end
height(image)
click to toggle source
# File lib/lolcommits/plugin/glitch.rb, line 117 def height(image) @height ||= image.rows end
wax_poetic()
click to toggle source
# File lib/lolcommits/plugin/glitch.rb, line 65 def wax_poetic chance = config_option(:glitch_probability) phrase = [ Faker::Hacker.say_something_smart, [Faker::Hacker.ingverb, Faker::Hacker.adjective, Faker::Hacker.noun].join(" "), Faker::Company.bs, Faker::ChuckNorris.fact, "awaiting particle strike", "detecting particle spin", "flipping #{chance} coins", "rolling D#{chance}", ].sample puts "Glitch probability generator warming up... #{phrase}" end
width(image)
click to toggle source
# File lib/lolcommits/plugin/glitch.rb, line 113 def width(image) @width ||= image.columns end