mykiwi/mykiwi.blogpublic Fork 0
b9bda7a8b01c38c6369f1e073f36bb851049f34b
Commits
Clone
git clone https://git.rickub.com/mykiwi/mykiwi.blog.git
git clone ssh://git@rickub.com/mykiwi/mykiwi.blog.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

Port fzakaria.com design to Hugo and add a homepage profile 1bdbd06 · on b9bda7a8b01c38c6369f1e073f36bb851049f34b · Romain Gautier · 20h ago
signal.html · 57 lines · 2.1 KBHTML Blame HistoryRaw
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
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
{{- /*
  Plots a Catmull-Rom curve through the 32 bytes of SHA-256(url), one sample
  per byte, emitted as an SVG path. Port of _plugins/signal.rb.
*/ -}}
{{- $url := . -}}
{{- $hash := crypto.SHA256 $url -}}
{{- $hexVal := dict "0" 0 "1" 1 "2" 2 "3" 3 "4" 4 "5" 5 "6" 6 "7" 7 "8" 8 "9" 9 "a" 10 "b" 11 "c" 12 "d" 13 "e" 14 "f" 15 -}}

{{- $width := 1000.0 -}}
{{- $height := 100.0 -}}
{{- $pad := 18.0 -}}
{{- $tension := 0.72 -}}
{{- $n := 32 -}}
{{- $last := sub $n 1 -}}
{{- $span := sub $height (mul 2 $pad) -}}
{{- $step := div $width (sub $n 1.0) -}}

{{- $bytes := slice -}}
{{- range $i := seq 0 $last -}}
  {{- $hi := index $hexVal (substr $hash (mul $i 2) 1) -}}
  {{- $lo := index $hexVal (substr $hash (add (mul $i 2) 1) 1) -}}
  {{- $bytes = $bytes | append (add (mul $hi 16) $lo) -}}
{{- end -}}

{{- $pts := slice -}}
{{- range $i, $b := $bytes -}}
  {{- $x := mul (float $i) $step -}}
  {{- $y := add $pad (mul (sub 1.0 (div (float $b) 255.0)) $span) -}}
  {{- $pts = $pts | append (dict "x" $x "y" $y) -}}
{{- end -}}

{{- $p0 := index $pts 0 -}}
{{- $d := printf "M%s,%s" (partial "signal-num.html" $p0.x) (partial "signal-num.html" $p0.y) -}}

{{- range $i := seq 0 (sub $last 1) -}}
  {{- $p0idx := 0 -}}
  {{- if ge $i 1 }}{{ $p0idx = sub $i 1 }}{{ end -}}
  {{- $p3idx := add $i 2 -}}
  {{- if gt $p3idx $last }}{{ $p3idx = $last }}{{ end -}}

  {{- $pp0 := index $pts $p0idx -}}
  {{- $pp1 := index $pts $i -}}
  {{- $pp2 := index $pts (add $i 1) -}}
  {{- $pp3 := index $pts $p3idx -}}

  {{- $c1x := add $pp1.x (mul (div (sub $pp2.x $pp0.x) 6.0) $tension) -}}
  {{- $c1y := add $pp1.y (mul (div (sub $pp2.y $pp0.y) 6.0) $tension) -}}
  {{- $c2x := sub $pp2.x (mul (div (sub $pp3.x $pp1.x) 6.0) $tension) -}}
  {{- $c2y := sub $pp2.y (mul (div (sub $pp3.y $pp1.y) 6.0) $tension) -}}

  {{- $d = printf "%s C%s,%s %s,%s %s,%s" $d
      (partial "signal-num.html" $c1x) (partial "signal-num.html" $c1y)
      (partial "signal-num.html" $c2x) (partial "signal-num.html" $c2y)
      (partial "signal-num.html" $pp2.x) (partial "signal-num.html" $pp2.y) -}}
{{- end -}}

{{- return (dict "hash" $hash "path" $d) -}}