Class: Turing::Image::RandomNoise

Inherits:
Turing::Image show all
Defined in:
lib/turing/image_plugins/random_noise.rb

Overview

Random Noise turing test

Generates random black noise, then text, then random white noise.

Instance Method Summary collapse

Methods inherited from Turing::Image

#initialize

Constructor Details

This class inherits a constructor from Turing::Image

Instance Method Details

#generate(img, word, bg = nil) ⇒ Object

contract method - generate the challenge



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/turing/image_plugins/random_noise.rb', line 15

def generate(img, word, bg = nil) # {{{
	fg = GD2::Color[255, 255, 255]
	bg = GD2::Color[0, 0, 0]
	
	0.upto(img.width * img.height * 0.4) do |i|
		img[rand(img.width), rand(img.height)] = bg
	end

	write_string(img, 'georgiai.ttf', bg, word, 48)
	
	quant = word.size > 7 ? 0.1 : 0.2
	0.upto(img.width * img.height * quant) do |i|
		img[rand(img.width), rand(img.height)] = fg
	end
end