-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnoise.rb
More file actions
32 lines (24 loc) · 738 Bytes
/
noise.rb
File metadata and controls
32 lines (24 loc) · 738 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
require 'chunky_png'
class Noise
class << self
def random_pixel(png)
[rand(png.dimension.width), rand(png.dimension.height)]
end
def invert_random(png)
coordinates = random_pixel png
png[*coordinates] = ChunkyPNG::Color(png[*coordinates] < 1000 ? 'white' : 'black')
end
def apply(noise_pixels)
# Move pattern files
system 'rm recognize/*.png'
system 'cp patterns/*.png recognize/'
# Add noize to each file
Dir['recognize/*.png'].each_with_index do |file, i|
png = ChunkyPNG::Image.from_file(file)
noise_pixels.times { invert_random png }
png.save file.gsub(/\/.*\.png/, "/#{i}.png")
File.delete file
end
end
end
end