Method: Favicon.create_blob

Defined in:
lib/wiki/favicon.rb

.create_blobObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/wiki/favicon.rb', line 6

def create_blob
  canvas = PNG::Canvas.new 32, 32
  light = PNG::Color.from_hsv(256*rand,200,255).rgb()
  dark = PNG::Color.from_hsv(256*rand,200,125).rgb()
  angle = 2 * (rand()-0.5)
  sin = Math.sin angle
  cos = Math.cos angle
  scale = sin.abs + cos.abs
  for x in (0..31)
    for y in (0..31)
      p = (sin >= 0 ? sin*x+cos*y : -sin*(31-x)+cos*y) / 31 / scale
      canvas[x,y] = PNG::Color.new(
        light[0]*p + dark[0]*(1-p),
        light[1]*p + dark[1]*(1-p),
        light[2]*p + dark[2]*(1-p))
    end
  end
  PNG.new(canvas).to_blob
end