-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathavatars.js
More file actions
42 lines (35 loc) · 1.7 KB
/
avatars.js
File metadata and controls
42 lines (35 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import colors from '../colors'
import svg from '../shapes'
export const base = 8
export const baseColors = 8
export const size = 24
export const total = Math.pow(base, 3) * Math.pow(baseColors, 3)
export let id = 0
function ri(total) {
return Math.floor(Math.random() * total)
}
export function random() {
// return `${ri(base)}${ri(baseColors)}${ri(base)}${ri(baseColors)}${ri(base)}${ri(baseColors)}`
return Math.floor(Math.random() * total + total).toString(base).substring(1)
}
export function outer(id, width) {
return `<svg ${width ? `width="${width}" height="${width}" ` : ''}viewBox="0 0 ${size} ${size}" xmlns="http://www.w3.org/2000/svg">`
+ inner(id)
+ `</svg>`
}
export function inner(value) {
const clipA = `clip-a-${id}`
const clipB = `clip-b-${id}`
const urlA = `url(#${clipA})`
const urlB = `url(#${clipB})`
const half = size / 2
++id
return `<defs><clipPath id="${clipA}"><rect width="${half + 1}" height="${size}" x="0" y="0"></rect></clipPath>`
+ `<clipPath id="${clipB}"><rect width="${half}" height="${size}" x="${half}" y="0"></rect></clipPath></defs>`
+ `<g style="fill: ${colors.bg[value[1]][0]}" clip-path="${urlA}">${svg.body[value[0]]}</g>`
+ `<g style="fill: ${colors.bg[value[1]][1]}" clip-path="${urlB}">${svg.body[value[0]]}</g>`
+ `<g style="fill: ${colors.fg[value[1]][value[3]][0]}" clip-path="${urlA}">${svg.eyes[value[2]]}</g>`
+ `<g style="fill: ${colors.fg[value[1]][value[3]][1]}" clip-path="${urlB}">${svg.eyes[value[2]]}</g>`
+ `<g style="fill: ${colors.fg[value[1]][value[5]][0]}" clip-path="${urlA}">${svg.mouth[value[4]]}</g>`
+ `<g style="fill: ${colors.fg[value[1]][value[5]][1]}" clip-path="${urlB}">${svg.mouth[value[4]]}</g>`
}