// Vikunja is a to-do list application to facilitate your life.
// Copyright 2018-2021 Vikunja and contributors. All rights reserved.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public Licensee as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public Licensee for more details.
//
// You should have received a copy of the GNU Affero General Public Licensee
// along with this program. If not, see .
package marble
import (
"math"
"strconv"
"code.vikunja.io/api/pkg/user"
)
// Provider generates a random avatar based on https://github.com/boringdesigners/boring-avatars
type Provider struct {
}
const avatarSize = 80
var colors = []string{
"#A3A948",
"#EDB92E",
"#F85931",
"#CE1836",
"#009989",
}
type props struct {
Color string
TranslateX int
TranslateY int
Rotate int
Scale float64
}
func getUnit(number int, rang, index int) int {
value := number % rang
digit := math.Floor(math.Mod(float64(number)/math.Pow(10, float64(index)), 10))
if index > 0 && (math.Mod(digit, 2) == 0) {
return -value
}
return value
}
func getPropsForUser(u *user.User) []*props {
ps := []*props{}
for i := 0; i < 3; i++ {
f := float64(getUnit(int(u.ID)*(i+1), avatarSize/10, 0))
ps = append(ps, &props{
Color: colors[(int(u.ID)+i)%(len(colors)-1)],
TranslateX: getUnit(int(u.ID)*(i+1), avatarSize/10, 1),
TranslateY: getUnit(int(u.ID)*(i+1), avatarSize/10, 2),
Scale: 1.2 + f/10,
Rotate: getUnit(int(u.ID)*(i+1), 360, 1),
})
}
return ps
}
func (p *Provider) GetAvatar(u *user.User, size int64) (avatar []byte, mimeType string, err error) {
s := strconv.FormatInt(size, 10)
avatarSizeStr := strconv.Itoa(avatarSize)
avatarSizeHalf := strconv.Itoa(avatarSize / 2)
ps := getPropsForUser(u)
return []byte(``), "image/svg+xml", nil
}