hex avatar experiment
Ted Unangst tedu@tedunangst.com
Sat, 22 Jan 2022 16:30:02 -0500
6 files changed,
39 insertions(+),
4 deletions(-)
M
activity.go
→
activity.go
@@ -1470,7 +1470,11 @@ a["mediaType"] = "image/png"
if ava := user.Options.Avatar; ava != "" { a["url"] = ava } else { - a["url"] = fmt.Sprintf("https://%s/a?a=%s", serverName, url.QueryEscape(user.URL)) + u := fmt.Sprintf("https://%s/a?a=%s", serverName, url.QueryEscape(user.URL)) + if user.Options.Avahex { + u += "&hex=1" + } + a["url"] = u } j["icon"] = a } else {
M
avatar.go
→
avatar.go
@@ -66,7 +66,7 @@ avatarcolors[i][3] = byte(c >> 0 & 0xff)
} } -func genAvatar(name string) []byte { +func genAvatar(name string, hex bool) []byte { h := sha512.New() h.Write([]byte(name)) s := h.Sum(nil)@@ -74,6 +74,27 @@ img := image.NewNRGBA(image.Rect(0, 0, 64, 64))
for i := 0; i < 64; i++ { for j := 0; j < 64; j++ { p := i*img.Stride + j*4 + if hex { + tan := 0.577 + if i < 32 { + if j < 17-int(float64(i)*tan) || j > 46+int(float64(i)*tan) { + img.Pix[p+0] = 0 + img.Pix[p+1] = 0 + img.Pix[p+2] = 0 + img.Pix[p+3] = 255 + continue + } + } else { + if j < 17-int(float64(64-i)*tan) || j > 46+int(float64(64-i)*tan) { + img.Pix[p+0] = 0 + img.Pix[p+1] = 0 + img.Pix[p+2] = 0 + img.Pix[p+3] = 255 + continue + + } + } + } xx := i/16*16 + j/16 x := s[xx] if x < 64 {
M
honk.go
→
honk.go
@@ -51,10 +51,11 @@
type UserOptions struct { SkinnyCSS bool `json:",omitempty"` OmitImages bool `json:",omitempty"` + Avahex bool `json:",omitempty"` + MentionAll bool `json:",omitempty"` Avatar string `json:",omitempty"` MapLink string `json:",omitempty"` Reaction string `json:",omitempty"` - MentionAll bool Chats int }
M
views/account.html
→
views/account.html
@@ -10,6 +10,8 @@ <p>about me:
<p><textarea name="whatabout">{{ .WhatAbout }}</textarea> <p><label class="button" for="skinny">skinny layout:</label> <input tabindex=1 type="checkbox" id="skinny" name="skinny" value="skinny" {{ if .User.Options.SkinnyCSS }}checked{{ end }}><span></span> +<p><label class="button" for="avahex">hex avatar:</label> +<input tabindex=1 type="checkbox" id="avahex" name="avahex" value="avahex" {{ if .User.Options.Avahex }}checked{{ end }}><span></span> <p><label class="button" for="omitimages">omit images:</label> <input tabindex=1 type="checkbox" id="omitimages" name="omitimages" value="omitimages" {{ if .User.Options.OmitImages }}checked{{ end }}><span></span> <p><label class="button" for="mentionall">mention all:</label>
M
web.go
→
web.go
@@ -1107,6 +1107,11 @@ options.SkinnyCSS = true
} else { options.SkinnyCSS = false } + if r.FormValue("avahex") == "avahex" { + options.Avahex = true + } else { + options.Avahex = false + } if r.FormValue("omitimages") == "omitimages" { options.OmitImages = true } else {@@ -2104,7 +2109,8 @@ if debugMode {
loadAvatarColors() } n := r.FormValue("a") - a := genAvatar(n) + hex := r.FormValue("hex") == "1" + a := genAvatar(n, hex) if !debugMode { w.Header().Set("Cache-Control", "max-age="+somedays()) }