class Rubatar::Avatar

Attributes

height[RW]
output[RW]
width[RW]

Public Class Methods

new(width, height, output) click to toggle source
# File lib/rubatar/avatar.rb, line 7
def initialize(width, height, output)
  @width = width
  @height = height
  @output = output
  @img = ChunkyPNG::Image.new(5, 5)
  @color = ChunkyPNG::Color.parse(Hash.seed)
end

Public Instance Methods

generate() click to toggle source
# File lib/rubatar/avatar.rb, line 20
def generate
  data = Array.new(25, 0)
  (0..5).each do |y|
    (0..5).each do |x|
      if x < 3
        data[x + y * 5] = (Hash::rand & 0x1).zero? ? 1 : 0
      else
        data[x + y * 5] = data[(4 - x) + y * 5];
      end
    end
  end

  data.each_with_index do |val, idx|
    unless val.zero?
      @img.set_pixel(idx % 5, idx / 5, @color)
    end
  end
end
save() click to toggle source
# File lib/rubatar/avatar.rb, line 39
def save
  #copy_img = ChunkyPNG::Image.new(5, 5)
  #copy_img.initialize_copy(@img)
  @img.resample_nearest_neighbor!(@width, @height)
  @img.save(@output)
end
size=(width, height) click to toggle source
# File lib/rubatar/avatar.rb, line 15
def size=(width, height)
  @width = width
  @height = height
end