summaryrefslogtreecommitdiff
path: root/_includes/extensions/trianglify.html
blob: 22003dc39e518e475a8e650f189ccde35dda8b18 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
{% if include.selector %}
  {% assign selector = include.selector %}
{% endif %}

{% if include.seed %}
  {% assign seed = include.seed %}
{% endif %}

<script src="https://cdnjs.cloudflare.com/ajax/libs/trianglify/2.0.0/trianglify.min.js"></script>
<script>
  function setRandomBgImage(selector, seed) {
    var element = document.querySelector(selector);
    if (!element) return;
    var pattern = Trianglify({
      width: screen.width,
      height: element.offsetHeight,
      seed: seed
    });
    element.appendChild(pattern.canvas());
  }

  setRandomBgImage('{{ selector }}', '{{ seed }}');
</script>