Archived
2
0
This repository has been archived on 2024-06-24. You can view files and clone it, but cannot push or open issues or pull requests.
neko-custom/client/src/components/avatar.vue

59 lines
1.3 KiB
Vue
Raw Normal View History

2020-10-19 01:39:31 +13:00
<template>
2020-10-19 02:13:12 +13:00
<!--
<img :src="`https://ui-avatars.com/api/?name=${seed}&size=${size}`" />
-->
2021-02-14 00:05:59 +13:00
<div
class="avatar"
:style="{
width: size + 'px',
height: size + 'px',
lineHeight: size + 'px',
fontSize: size / 2 + 'px',
backgroundColor: Background(seed),
}"
>
2020-10-19 02:13:12 +13:00
{{ seed.substring(0, 2).toUpperCase() }}
</div>
2020-10-19 01:39:31 +13:00
</template>
2020-10-19 02:13:12 +13:00
<style lang="scss" scoped>
.avatar {
user-select: none;
text-align: center;
background: white;
color: black;
display: inline-block;
overflow: hidden;
border-radius: 50%;
}
</style>
2020-10-19 01:39:31 +13:00
<script lang="ts">
import { Vue, Component, Prop } from 'vue-property-decorator'
@Component({
name: 'neko-avatar',
})
export default class extends Vue {
2021-02-14 00:05:59 +13:00
@Prop(String) readonly seed: string | undefined
@Prop(Number) readonly size: number | undefined
2020-10-19 02:13:12 +13:00
2020-10-19 04:19:23 +13:00
Background(seed: string) {
2021-02-14 00:05:59 +13:00
let a = 0,
b = 0,
c = 0
for (let i = 0; i < seed.length; i++) {
a += seed.charCodeAt(i) * 3
b += seed.charCodeAt(i) * 5
c += seed.charCodeAt(i) * 7
2020-10-19 02:13:12 +13:00
}
2021-02-14 00:05:59 +13:00
let x = Math.floor(128 + (a % 128))
let y = Math.floor(128 + (b % 128))
let z = Math.floor(128 + (c % 128))
return 'rgb(' + x + ',' + y + ',' + z + ')'
2020-10-19 02:13:12 +13:00
}
2020-10-19 01:39:31 +13:00
}
</script>