enhance(server): tweak identicon generation

This commit is contained in:
syuilo 2022-07-09 13:22:35 +09:00
parent 4ac75243e5
commit 522ddba3d7

View File

@ -7,28 +7,31 @@ import { WriteStream } from 'node:fs';
import * as p from 'pureimage'; import * as p from 'pureimage';
import gen from 'random-seed'; import gen from 'random-seed';
const size = 256; // px const size = 128; // px
const n = 5; // resolution const n = 5; // resolution
const margin = (size / n); const margin = (size / 4);
const colors = [ const colors = [
'#e57373', ['#FF512F', '#DD2476'],
'#F06292', ['#FF61D2', '#FE9090'],
'#BA68C8', ['#72FFB6', '#10D164'],
'#9575CD', ['#FD8451', '#FFBD6F'],
'#7986CB', ['#305170', '#6DFC6B'],
'#64B5F6', ['#00C0FF', '#4218B8'],
'#4FC3F7', ['#009245', '#FCEE21'],
'#4DD0E1', ['#0100EC', '#FB36F4'],
'#4DB6AC', ['#FDABDD', '#374A5A'],
'#81C784', ['#38A2D7', '#561139'],
'#8BC34A', ['#121C84', '#8278DA'],
'#AFB42B', ['#5761B2', '#1FC5A8'],
'#F57F17', ['#FFDB01', '#0E197D'],
'#FF5722', ['#FF3E9D', '#0E1F40'],
'#795548', ['#766eff', '#00d4ff'],
'#455A64', ['#9bff6e', '#00d4ff'],
['#ff6e94', '#00d4ff'],
['#ffa96e', '#00d4ff'],
['#ffa96e', '#ff009d'],
['#ffdd6e', '#ff009d'],
]; ];
const bg = '#e9e9e9';
const actualSize = size - (margin * 2); const actualSize = size - (margin * 2);
const cellSize = actualSize / n; const cellSize = actualSize / n;
@ -42,11 +45,17 @@ export function genIdenticon(seed: string, stream: WriteStream): Promise<void> {
const canvas = p.make(size, size, undefined); const canvas = p.make(size, size, undefined);
const ctx = canvas.getContext('2d'); const ctx = canvas.getContext('2d');
const bgColors = colors[rand(colors.length)];
const bg = ctx.createLinearGradient(0, 0, size, size);
bg.addColorStop(0, bgColors[0]);
bg.addColorStop(1, bgColors[1]);
ctx.fillStyle = bg; ctx.fillStyle = bg;
ctx.beginPath(); ctx.beginPath();
ctx.fillRect(0, 0, size, size); ctx.fillRect(0, 0, size, size);
ctx.fillStyle = colors[rand(colors.length)]; ctx.fillStyle = '#ffffff';
// side bitmap (filled by false) // side bitmap (filled by false)
const side: boolean[][] = new Array(sideN); const side: boolean[][] = new Array(sideN);