Module: BoringAvatars::Variants::Pixel

Defined in:
lib/boring_avatars/variants/pixel.rb

Constant Summary collapse

SIZE =
80
ELEMENTS =
64
TOP_ROW_X =
[0, 20, 40, 60, 10, 30, 50, 70].freeze
COLUMN_X =
[0, 20, 40, 60, 10, 30, 50, 70].freeze
Y_COORDINATES =
(10..70).step(10).to_a.freeze
COORDINATES =
(
  TOP_ROW_X.map { |x| [x, 0] } +
  COLUMN_X.flat_map { |x| Y_COORDINATES.map { |y| [x, y] } }
).freeze

Class Method Summary collapse

Class Method Details

.render(input:, hash:, ids:) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/boring_avatars/variants/pixel.rb', line 23

def render(input:, hash:, ids:)
  colors = Array.new(ELEMENTS) do |index|
    Utilities.random_color(hash % (index + 1), input.colors)
  end
  content = COORDINATES.each_with_index.map do |(x, y), index|
    element(
      "rect",
      {
        "x" => x.zero? ? nil : x,
        "y" => y.zero? ? nil : y,
        "width" => 10,
        "height" => 10,
        "fill" => colors[index]
      }
    )
  end

  VariantResult.new(
    size: SIZE,
    content: content,
    mask_attributes: { "mask-type" => "alpha" }
  )
end