mykiwi/mykiwi.blogpublic Fork 0
f8c7bc5befe025e055b2734f5317ed645047d40e
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.

signal.html · 57 lines · 2.1 KBHTML Blame HistoryRaw
Port fzakaria.com design to Hugo and add a homepage profile 1bdbd06 Romain Gautier 21h ago1{{- /*
2 Plots a Catmull-Rom curve through the 32 bytes of SHA-256(url), one sample
3 per byte, emitted as an SVG path. Port of _plugins/signal.rb.
4*/ -}}
5{{- $url := . -}}
6{{- $hash := crypto.SHA256 $url -}}
7{{- $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 -}}
8
9{{- $width := 1000.0 -}}
10{{- $height := 100.0 -}}
11{{- $pad := 18.0 -}}
12{{- $tension := 0.72 -}}
13{{- $n := 32 -}}
14{{- $last := sub $n 1 -}}
15{{- $span := sub $height (mul 2 $pad) -}}
16{{- $step := div $width (sub $n 1.0) -}}
17
18{{- $bytes := slice -}}
19{{- range $i := seq 0 $last -}}
20 {{- $hi := index $hexVal (substr $hash (mul $i 2) 1) -}}
21 {{- $lo := index $hexVal (substr $hash (add (mul $i 2) 1) 1) -}}
22 {{- $bytes = $bytes | append (add (mul $hi 16) $lo) -}}
23{{- end -}}
24
25{{- $pts := slice -}}
26{{- range $i, $b := $bytes -}}
27 {{- $x := mul (float $i) $step -}}
28 {{- $y := add $pad (mul (sub 1.0 (div (float $b) 255.0)) $span) -}}
29 {{- $pts = $pts | append (dict "x" $x "y" $y) -}}
30{{- end -}}
31
32{{- $p0 := index $pts 0 -}}
33{{- $d := printf "M%s,%s" (partial "signal-num.html" $p0.x) (partial "signal-num.html" $p0.y) -}}
34
35{{- range $i := seq 0 (sub $last 1) -}}
36 {{- $p0idx := 0 -}}
37 {{- if ge $i 1 }}{{ $p0idx = sub $i 1 }}{{ end -}}
38 {{- $p3idx := add $i 2 -}}
39 {{- if gt $p3idx $last }}{{ $p3idx = $last }}{{ end -}}
40
41 {{- $pp0 := index $pts $p0idx -}}
42 {{- $pp1 := index $pts $i -}}
43 {{- $pp2 := index $pts (add $i 1) -}}
44 {{- $pp3 := index $pts $p3idx -}}
45
46 {{- $c1x := add $pp1.x (mul (div (sub $pp2.x $pp0.x) 6.0) $tension) -}}
47 {{- $c1y := add $pp1.y (mul (div (sub $pp2.y $pp0.y) 6.0) $tension) -}}
48 {{- $c2x := sub $pp2.x (mul (div (sub $pp3.x $pp1.x) 6.0) $tension) -}}
49 {{- $c2y := sub $pp2.y (mul (div (sub $pp3.y $pp1.y) 6.0) $tension) -}}
50
51 {{- $d = printf "%s C%s,%s %s,%s %s,%s" $d
52 (partial "signal-num.html" $c1x) (partial "signal-num.html" $c1y)
53 (partial "signal-num.html" $c2x) (partial "signal-num.html" $c2y)
54 (partial "signal-num.html" $pp2.x) (partial "signal-num.html" $pp2.y) -}}
55{{- end -}}
56
57{{- return (dict "hash" $hash "path" $d) -}}