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

53 lines
1.2 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}`" />
-->
<div class="avatar" :style="{
width: size + 'px',
height: size + 'px',
lineHeight: size + 'px',
fontSize: (size/2) + 'px',
backgroundColor: Background(),
}">
{{ 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 {
2020-10-19 02:13:12 +13:00
@Prop(String) readonly seed: string | undefined;
@Prop(Number) readonly size: number | undefined;
Background() {
let a = 0, b = 0, c = 0;
for(let i = 0; i < this.seed.length; i++) {
a += this.seed.charCodeAt(i) * 3;
b += this.seed.charCodeAt(i) * 5;
c += this.seed.charCodeAt(i) * 7;
}
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 01:39:31 +13:00
}
</script>