misc

Misc scripts and tools
git clone git://git.alexwennerberg.com/misc
Log | Files | Refs | README | LICENSE

commit 9ab4dfe725286605eed23197c706bf5882ca97ea
parent 2f2183cd2349530513ca8aa7b2d856827ea9d61e
Author: alex wennerberg <awennerb@twitch.tv>
Date:   Wed, 10 Nov 2021 10:29:30 -0500

simplify avatar gen code

Diffstat:
Mavatar.go | 22++--------------------
1 file changed, 2 insertions(+), 20 deletions(-)

diff --git a/avatar.go b/avatar.go @@ -51,26 +51,8 @@ func genAvatar(name string) []byte { p := i*img.Stride + j*4 xx := i/(size/4)*16 + j/(size/4) x := s[xx] - if x < 64 { - img.Pix[p+0] = avatarcolors[0][0] - img.Pix[p+1] = avatarcolors[0][1] - img.Pix[p+2] = avatarcolors[0][2] - img.Pix[p+3] = avatarcolors[0][3] - } else if x < 128 { - img.Pix[p+0] = avatarcolors[1][0] - img.Pix[p+1] = avatarcolors[1][1] - img.Pix[p+2] = avatarcolors[1][2] - img.Pix[p+3] = avatarcolors[1][3] - } else if x < 192 { - img.Pix[p+0] = avatarcolors[2][0] - img.Pix[p+1] = avatarcolors[2][1] - img.Pix[p+2] = avatarcolors[2][2] - img.Pix[p+3] = avatarcolors[2][3] - } else { - img.Pix[p+0] = avatarcolors[3][0] - img.Pix[p+1] = avatarcolors[3][1] - img.Pix[p+2] = avatarcolors[3][2] - img.Pix[p+3] = avatarcolors[3][3] + for n := 0; n < 4; n++ { + img.Pix[p+n] = avatarcolors[x/64][n] } } }