
{% macro avgcolor(color1, color2) -%}
    {%- set color1 = rgbcolor(color1) -%}
    {%- set color2 = rgbcolor(color2) -%}
    {%- set coloravg = [
        mean([color1[0], color2[0]]),
        mean([color1[1], color2[1]]),
        mean([color1[2], color2[2]])
    ] -%}
    {{ hexcolor(coloravg) }}
{%- endmacro %}

{% macro lighten(color, fraction) -%}
    {%- set color = rgbcolor(color) -%}
    {%- set add_white = 255 * fraction -%}
    {%- set new_r = color[0] + add_white -%}
    {%- set new_g = color[1] + add_white -%}
    {%- set new_b = color[2] + add_white -%}
    {%- if new_r > 255 %}{% set new_r = 255 %}{% endif -%}
    {%- if new_g > 255 %}{% set new_g = 255 %}{% endif -%}
    {%- if new_b > 255 %}{% set new_b = 255 %}{% endif -%}
    {{ hexcolor([new_r, new_g, new_b]) }}
{%- endmacro %}

{% macro darken(color, fraction) -%}
    {%- set color = rgbcolor(color) -%}
    {%- set darkcolor = [
        color[0] - (color[0] * fraction),
        color[1] - (color[1] * fraction),
        color[2] - (color[2] * fraction),
    ] -%}
    {{ hexcolor(darkcolor) }}
{%- endmacro %}
