This commit is contained in:
6543 2021-02-02 03:02:14 +01:00
parent e339735667
commit c868879277
No known key found for this signature in database
GPG Key ID: C99B82E40B027BAE

View File

@ -17,9 +17,8 @@ func MakeAvatar(seedString string) string {
}
if seed&1 == 0 {
return femaleAvatar(seed, "")
} else {
return maleAvatar(seed, "")
}
return maleAvatar(seed, "")
}
/**
@ -102,14 +101,14 @@ func f2hsv(h, s, v float64) *hsv {
return c
}
func to_rgb(s string) *rgb {
func toRgb(s string) *rgb {
c := new(rgb)
c.a = 255
fmt.Sscanf(s, "#%02x%02x%02x", &c.r, &c.g, &c.b)
return c
}
func (c *rgb) to_hsv() *hsv {
func (c *rgb) toHsv() *hsv {
var h float64
var s float64
var v float64
@ -142,7 +141,7 @@ func (c *rgb) to_hsv() *hsv {
return f2hsv(h, s, v)
}
func (c *hsv) to_rgb() *rgb {
func (c *hsv) toRgb() *rgb {
h := int((c.h / 60))
f := c.h/60 - float64(h)
p := c.v * (1 - c.s)
@ -167,8 +166,8 @@ func (c *hsv) to_rgb() *rgb {
}
func (c *rgb) brighterThan(ref *rgb, delta float64) *rgb {
primary := c.to_hsv()
secondary := ref.to_hsv()
primary := c.toHsv()
secondary := ref.toHsv()
if primary.v >= secondary.v+delta {
return c
}
@ -176,12 +175,12 @@ func (c *rgb) brighterThan(ref *rgb, delta float64) *rgb {
if primary.v > 360 {
primary.v = 360
}
return primary.to_rgb()
return primary.toRgb()
}
func (c *rgb) darkerThan(ref *rgb, delta float64) *rgb {
primary := c.to_hsv()
secondary := ref.to_hsv()
primary := c.toHsv()
secondary := ref.toHsv()
if primary.v <= secondary.v-delta {
return c
}
@ -189,17 +188,16 @@ func (c *rgb) darkerThan(ref *rgb, delta float64) *rgb {
if primary.v < 0 {
primary.v = 0
}
return primary.to_rgb()
return primary.toRgb()
}
func (c *rgb) brighterOrDarkerThan(ref *rgb, delta float64) *rgb {
primary := c.to_hsv()
secondary := ref.to_hsv()
primary := c.toHsv()
secondary := ref.toHsv()
if primary.v <= secondary.v {
return c.darkerThan(ref, delta)
} else {
return c.brighterThan(ref, delta)
}
return c.brighterThan(ref, delta)
}
func (c *rgb) withAlpha(alpha float64) *rgb {
@ -216,16 +214,16 @@ func (c *rgb) html() string {
func maleAvatar(seed uint64, mood string) string {
var g = linearCongruentialGenerator(seed)
var skinColor = to_rgb(g.pickOne([]string{"#FFDBAC", "#F5CFA0", "#EAC393", "#E0B687", "#CB9E6E", "#B68655", "#A26D3D", "#8D5524"}))
var hairColor = to_rgb(g.pickOne([]string{"#090806", "#2c222b", "#71635a", "#b7a69e", "#b89778", "#a56b46", "#b55239", "#8d4a43",
var skinColor = toRgb(g.pickOne([]string{"#FFDBAC", "#F5CFA0", "#EAC393", "#E0B687", "#CB9E6E", "#B68655", "#A26D3D", "#8D5524"}))
var hairColor = toRgb(g.pickOne([]string{"#090806", "#2c222b", "#71635a", "#b7a69e", "#b89778", "#a56b46", "#b55239", "#8d4a43",
"#91553d", "#533d32", "#3b3024", "#554838", "#4e433f", "#504444", "#6a4e42", "#a7856a", "#977961"})).brighterOrDarkerThan(skinColor, 17)
var eyesColor = to_rgb(g.pickOne([]string{"#76778b", "#697b94", "#647b90", "#5b7c8b", "#588387"}))
var eyesColor = toRgb(g.pickOne([]string{"#76778b", "#697b94", "#647b90", "#5b7c8b", "#588387"}))
var eyebrowsColor = hairColor.darkerThan(skinColor, 7).darkerThan(hairColor, 10)
var mustacheColor = hairColor.darkerThan(skinColor, 7).withAlpha(g.pickOneFloat([]float64{1, 0.75, 0.5}))
var mouthColor = to_rgb(g.pickOne([]string{"#eec1ad", "#dbac98", "#d29985"})).brighterOrDarkerThan(skinColor, 10)
var glassesColor = to_rgb(g.pickOne([]string{"#5f705c", "#43677d", "#5e172d", "#ffb67a", "#a04b5d", "#191919", "#323232", "#4b4b4b"}))
var clothesColor = to_rgb(g.pickOne([]string{"#5bc0de", "#5cb85c", "#428bca", "#03396c", "#005b96", "#6497b1", "#1b85b8", "#5a5255", "#559e83", "#ae5a41", "#c3cb71", "#666547", "#ffe28a"}))
var hatColor = to_rgb(g.pickOne([]string{"#18293b", "#2e1e05", "#989789", "#3d6ba7", "#517459", "#a62116"}))
var mouthColor = toRgb(g.pickOne([]string{"#eec1ad", "#dbac98", "#d29985"})).brighterOrDarkerThan(skinColor, 10)
var glassesColor = toRgb(g.pickOne([]string{"#5f705c", "#43677d", "#5e172d", "#ffb67a", "#a04b5d", "#191919", "#323232", "#4b4b4b"}))
var clothesColor = toRgb(g.pickOne([]string{"#5bc0de", "#5cb85c", "#428bca", "#03396c", "#005b96", "#6497b1", "#1b85b8", "#5a5255", "#559e83", "#ae5a41", "#c3cb71", "#666547", "#ffe28a"}))
var hatColor = toRgb(g.pickOne([]string{"#18293b", "#2e1e05", "#989789", "#3d6ba7", "#517459", "#a62116"}))
if mood == "" {
mood = g.pickOne([]string{"sad", "happy", "surprised"})
@ -377,18 +375,18 @@ func maleAvatar(seed uint64, mood string) string {
func femaleAvatar(seed uint64, mood string) string {
var g = linearCongruentialGenerator(seed)
var skinColor = to_rgb(g.pickOne([]string{"#FFDBAC", "#F5CFA0", "#EAC393", "#E0B687", "#CB9E6E", "#B68655", "#A26D3D", "#8D5524"}))
var hairColor = to_rgb(g.pickOne([]string{"#090806", "#2c222b", "#71635a", "#b7a69e", "#d6c4c2", "#cabfb1", "#dcd0ba", "#fff5e1",
var skinColor = toRgb(g.pickOne([]string{"#FFDBAC", "#F5CFA0", "#EAC393", "#E0B687", "#CB9E6E", "#B68655", "#A26D3D", "#8D5524"}))
var hairColor = toRgb(g.pickOne([]string{"#090806", "#2c222b", "#71635a", "#b7a69e", "#d6c4c2", "#cabfb1", "#dcd0ba", "#fff5e1",
"#e6cea8", "#e5c8a8", "#debc99", "#b89778", "#a56b46", "#b55239", "#8d4a43", "#91553d",
"#533d32", "#3b3024", "#554838", "#4e433f", "#504444", "#6a4e42", "#a7856a", "#977961"})).brighterOrDarkerThan(skinColor, 17)
var eyesColor = to_rgb(g.pickOne([]string{"#76778b", "#697b94", "#647b90", "#5b7c8b", "#588387"}))
var eyesColor = toRgb(g.pickOne([]string{"#76778b", "#697b94", "#647b90", "#5b7c8b", "#588387"}))
var eyebrowsColor = hairColor.darkerThan(skinColor, 7).darkerThan(hairColor, 10)
var accessoriesColor = to_rgb(g.pickOne([]string{"#daa520", "#ffd700", "#eee8aa", "#fafad2", "#d3d3d3", "#a9a9a9"}))
var mouthColor = to_rgb(g.pickOne([]string{"#dbac98", "#d29985", "#c98276", "#e35d6a", "#e32153", "#de0f0d"})).brighterOrDarkerThan(skinColor, 10)
var glassesColor = to_rgb(g.pickOne([]string{"#5f705c", "#43677d", "#5e172d", "#ffb67a", "#a04b5d", "#191919", "#323232", "#4b4b4b"}))
var clothesColor = to_rgb(g.pickOne([]string{"#d11141", "#00b159", "#00aedb", "#f37735", "#ffc425", "#740001", "#ae0001", "#eeba30",
var accessoriesColor = toRgb(g.pickOne([]string{"#daa520", "#ffd700", "#eee8aa", "#fafad2", "#d3d3d3", "#a9a9a9"}))
var mouthColor = toRgb(g.pickOne([]string{"#dbac98", "#d29985", "#c98276", "#e35d6a", "#e32153", "#de0f0d"})).brighterOrDarkerThan(skinColor, 10)
var glassesColor = toRgb(g.pickOne([]string{"#5f705c", "#43677d", "#5e172d", "#ffb67a", "#a04b5d", "#191919", "#323232", "#4b4b4b"}))
var clothesColor = toRgb(g.pickOne([]string{"#d11141", "#00b159", "#00aedb", "#f37735", "#ffc425", "#740001", "#ae0001", "#eeba30",
"#96ceb4", "#ffeead", "#ff6f69", "#ffcc5c", "#88d8b0"}))
var hatColor = to_rgb(g.pickOne([]string{"#cc6192", "#2663a3", "#a62116", "#3d8a6b", "#614f8a"}))
var hatColor = toRgb(g.pickOne([]string{"#cc6192", "#2663a3", "#a62116", "#3d8a6b", "#614f8a"}))
if mood == "" {
mood = g.pickOne([]string{"sad", "happy", "surprised"})