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',
|
2020-10-19 04:19:23 +13:00
|
|
|
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 {
|
2020-10-19 02:13:12 +13:00
|
|
|
@Prop(String) readonly seed: string | undefined;
|
|
|
|
@Prop(Number) readonly size: number | undefined;
|
|
|
|
|
2020-10-19 04:19:23 +13:00
|
|
|
Background(seed: string) {
|
2020-10-19 02:13:12 +13:00
|
|
|
let a = 0, b = 0, c = 0;
|
2020-10-19 04:19:23 +13:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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>
|