16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/boring_avatars/variants/bauhaus.rb', line 16
def render(input:, hash:, ids:)
properties = Array.new(ELEMENTS) do |index|
multiplier = index + 1
{
color: Utilities.random_color(hash + index, input.colors),
translate_x: Utilities.unit(hash * multiplier, (SIZE / 2) - (index + 17), 1),
translate_y: Utilities.unit(hash * multiplier, (SIZE / 2) - (index + 17), 2),
rotate: Utilities.unit(hash * multiplier, 360),
square: Utilities.boolean(hash, 2)
}
end
content = [
element("rect", { "width" => SIZE, "height" => SIZE, "fill" => properties[0][:color] }),
element(
"rect",
{
"x" => (SIZE - 60) / 2,
"y" => (SIZE - 20) / 2,
"width" => SIZE,
"height" => properties[1][:square] ? SIZE : SIZE / 8,
"fill" => properties[1][:color],
"transform" => transform(properties[1])
}
),
element(
"circle",
{
"cx" => SIZE / 2,
"cy" => SIZE / 2,
"fill" => properties[2][:color],
"r" => SIZE / 5,
"transform" => "translate(#{number(properties[2][:translate_x])} #{number(properties[2][:translate_y])})"
}
),
element(
"line",
{
"x1" => 0,
"y1" => SIZE / 2,
"x2" => SIZE,
"y2" => SIZE / 2,
"stroke-width" => 2,
"stroke" => properties[3][:color],
"transform" => transform(properties[3])
}
)
]
VariantResult.new(size: SIZE, content: content)
end
|