{{- /* 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) -}}