@kodax-ai/botui 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +140 -113
- package/core/identity.js +46 -0
- package/{themes/solids → core}/motion.js +114 -114
- package/core/registry.js +26 -18
- package/docs/usage.md +202 -0
- package/element.js +5 -0
- package/index.d.ts +2 -0
- package/index.js +11 -5
- package/package.json +38 -2
- package/themes/caret/README.md +43 -0
- package/themes/caret/avatar.js +10 -0
- package/themes/caret/engine.js +143 -0
- package/themes/caret/index.d.ts +24 -0
- package/themes/caret/index.js +35 -0
- package/themes/critter/README.md +43 -0
- package/themes/critter/avatar.js +12 -0
- package/themes/critter/engine.js +113 -0
- package/themes/critter/index.d.ts +28 -0
- package/themes/critter/index.js +35 -0
- package/themes/doodle/README.md +43 -0
- package/themes/doodle/avatar.js +10 -0
- package/themes/doodle/engine.js +149 -0
- package/themes/doodle/index.d.ts +24 -0
- package/themes/doodle/index.js +36 -0
- package/themes/dots/README.md +42 -0
- package/themes/dots/avatar.js +15 -0
- package/themes/dots/engine.js +179 -0
- package/themes/dots/index.d.ts +24 -0
- package/themes/dots/index.js +35 -0
- package/themes/kaomoji/README.md +42 -0
- package/themes/kaomoji/avatar.js +10 -0
- package/themes/kaomoji/engine.js +110 -0
- package/themes/kaomoji/index.d.ts +24 -0
- package/themes/kaomoji/index.js +35 -0
- package/themes/liquid/README.md +47 -0
- package/themes/liquid/avatar.js +10 -0
- package/themes/liquid/engine.js +161 -0
- package/themes/liquid/index.d.ts +24 -0
- package/themes/liquid/index.js +35 -0
- package/themes/matrix/README.md +48 -0
- package/themes/matrix/avatar.js +227 -0
- package/themes/matrix/engine.js +479 -0
- package/themes/matrix/index.d.ts +47 -0
- package/themes/matrix/index.js +34 -0
- package/themes/orb/README.md +44 -0
- package/themes/orb/avatar.js +10 -0
- package/themes/orb/engine.js +130 -0
- package/themes/orb/index.d.ts +24 -0
- package/themes/orb/index.js +36 -0
- package/themes/solids/README.md +2 -2
- package/themes/solids/avatar.js +561 -579
- package/themes/solids/face.js +52 -56
- package/themes/solids/index.js +34 -28
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# 像素生物 critter
|
|
2
|
+
|
|
3
|
+
一只像素画小生物:方块像素拼成的身体、两只脚,耳朵就是外形(猫耳、熊耳、兔耳、天线)。脸是点阵主题的 5×5 屏幕,每种眼神和信号都画成身体上的像素。工作时原地踏步,累了或卡住时坐下;猫会抖耳朵,兔子难过时耳朵耷拉,天线在思考时一闪一闪。
|
|
4
|
+
|
|
5
|
+
来自 avatar-lab 的草图方向 J(像素生物),2026-11-28 做成主题。
|
|
6
|
+
|
|
7
|
+
## 用法
|
|
8
|
+
|
|
9
|
+
```js
|
|
10
|
+
import {createAvatar} from '@kodax-ai/botui/themes/critter'; // 或相对路径 ./themes/critter/index.js
|
|
11
|
+
|
|
12
|
+
const bot = createAvatar({identity: 'research-bot', size: 36});
|
|
13
|
+
sidebar.append(bot.el);
|
|
14
|
+
bot.setState('thinking');
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
从总入口用:先 `import '@kodax-ai/botui/themes/critter'`,再 `createAvatar({theme: 'critter', ...})`。自定义元素:同样先加载主题脚本,再写 `<bot-avatar theme="critter" identity="research-bot"></bot-avatar>`。
|
|
18
|
+
|
|
19
|
+
## 与点阵的关系
|
|
20
|
+
|
|
21
|
+
颜色、眼型、动作、记号、粒子、交互、水印都和 [点阵](../matrix/README.md) 一样,选项和方法也相同;同一个 Bot ID 在两个主题里是同一种颜色和眼型。不同的是:
|
|
22
|
+
|
|
23
|
+
| 项 | 像素生物 |
|
|
24
|
+
|---|---|
|
|
25
|
+
| `shape` | 耳朵:`cat` 猫耳、`bear` 熊耳、`bunny` 兔耳、`antenna` 天线。由 Bot ID 稳定决定,和点阵的外形是两套 |
|
|
26
|
+
| 脸 | 点阵的 `FACES` 和 `SCREENS` 原样使用,亮的点画成深色像素,不亮的不画 |
|
|
27
|
+
| 坐下 | 睡觉、阻塞、困、无聊、难过、出错、关机时脚收起、身体下沉 |
|
|
28
|
+
| 踏步 | 工作、编码、运行、控制、搜索、发送、接收、上传时两只脚轮流抬起 |
|
|
29
|
+
| 耳朵 | 猫隔几秒抖一下耳朵;兔子在难过、困、出错、害怕时耳朵耷拉;天线的灯在思考、计算、加载、聆听时闪 |
|
|
30
|
+
| 背面 | 转到背面只有身体,没有脸 |
|
|
31
|
+
|
|
32
|
+
## 纯模型
|
|
33
|
+
|
|
34
|
+
`createCritter(options)` 与 `createMatrix` 用法相同,`shape` 换成耳朵的名字。不碰 DOM、不用时钟和 `Math.random`,同样的输入永远得到同样的帧。
|
|
35
|
+
|
|
36
|
+
## 文件
|
|
37
|
+
|
|
38
|
+
| 文件 | 内容 |
|
|
39
|
+
|---|---|
|
|
40
|
+
| `index.js` | 入口:`createAvatar`、`theme` 和各种表 |
|
|
41
|
+
| `avatar.js` | `CritterAvatar`:继承点阵的 `MatrixAvatar`,换模型和外形表 |
|
|
42
|
+
| `engine.js` | 像素身体、耳朵表、坐下和踏步;脸用点阵的 `lit()` |
|
|
43
|
+
| `playground.html` | 试玩页(共用 `../solids/playground.js`) |
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import {MatrixAvatar, identityFrom as tileIdentity} from '../matrix/avatar.js';
|
|
2
|
+
import {createCritter, critterShapes} from './engine.js';
|
|
3
|
+
|
|
4
|
+
/** The look a Bot ID maps to: one of the critters, and the same colour and eye style as in every theme. */
|
|
5
|
+
export const identityFrom = (identity, pool) => tileIdentity(identity, pool, critterShapes);
|
|
6
|
+
|
|
7
|
+
/** The pixel critter avatar: the matrix avatar with a pixel creature for a body. Options and methods as MatrixAvatar's; `shape` is one of critterShapes. */
|
|
8
|
+
export class CritterAvatar extends MatrixAvatar {
|
|
9
|
+
static className = 'botui-critter';
|
|
10
|
+
static shapes = critterShapes;
|
|
11
|
+
createModel(options) { return createCritter(options); }
|
|
12
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// The pixel critter theme's model: a little pixel-art creature, with the matrix theme's face.
|
|
2
|
+
//
|
|
3
|
+
// The body is a block of square pixels with ears (cat, bear, bunny, or an
|
|
4
|
+
// antenna: that is the shape) and two feet. The face is the matrix theme's 5x5
|
|
5
|
+
// screen, every expression and every signal, drawn as pixels on the body. It
|
|
6
|
+
// walks in place while it works, sits down when it is tired or stuck, a cat
|
|
7
|
+
// twitches an ear, a bunny's ears flop when it is sad, an antenna blinks while
|
|
8
|
+
// it thinks.
|
|
9
|
+
//
|
|
10
|
+
// Everything else (motion, marks, particles, halo, handling) is the matrix
|
|
11
|
+
// model's. Pure, like it: no DOM, no clock, no Math.random.
|
|
12
|
+
// Sketched in avatar-lab as direction J (像素生物), made a theme on 2026-11-28.
|
|
13
|
+
|
|
14
|
+
import {Matrix} from '../matrix/engine.js';
|
|
15
|
+
import {ease} from '../../core/core.js';
|
|
16
|
+
|
|
17
|
+
const {max, floor} = Math;
|
|
18
|
+
const fixed = v => v.toFixed(2);
|
|
19
|
+
// A 9 x 11 grid: ears in rows 0-2, the body in rows 3-9, feet in row 10; the face's 5x5 sits at columns 2-6, rows 4-8.
|
|
20
|
+
const CELL = 7.6, COLS = 9, X0 = 50 - COLS / 2 * CELL, Y0 = 50 - 5.5 * CELL, FACE = [2, 4], SEAM = 0.35, BLUSH = 'oklch(0.74 0.17 15)';
|
|
21
|
+
|
|
22
|
+
const BODY = [];
|
|
23
|
+
for (let r = 3; r <= 9; r++) for (let c = 0; c < COLS; c++) if (!((r === 3 || r === 9) && (c === 0 || c === COLS - 1))) BODY.push([c, r]);
|
|
24
|
+
|
|
25
|
+
/** The ears: (t, mood) -> pixels [col, row]. */
|
|
26
|
+
const EARS = {
|
|
27
|
+
cat: (t, mood) => { const twitch = !mood.down && t % 4.3 < 0.18; return [[twitch ? 0 : 1, 1], [7, 1], [1, 2], [2, 2], [6, 2], [7, 2]]; },
|
|
28
|
+
bear: () => [[1, 1], [2, 1], [6, 1], [7, 1], [0, 2], [1, 2], [2, 2], [6, 2], [7, 2], [8, 2]],
|
|
29
|
+
bunny: (t, mood) => mood.down ? [[0, 2], [1, 2], [2, 2], [6, 2], [7, 2], [8, 2]] : [[2, 0], [6, 0], [2, 1], [6, 1], [2, 2], [6, 2]],
|
|
30
|
+
antenna: () => [[4, 1], [4, 2]],
|
|
31
|
+
};
|
|
32
|
+
export const critterShapes = Object.freeze(Object.keys(EARS));
|
|
33
|
+
/** The critters, in the same form as the solids' SHAPES. */
|
|
34
|
+
export const SHAPES = [
|
|
35
|
+
{name: 'cat', zh: '猫耳', group: 'critter'},
|
|
36
|
+
{name: 'bear', zh: '熊耳', group: 'critter'},
|
|
37
|
+
{name: 'bunny', zh: '兔耳', group: 'critter'},
|
|
38
|
+
{name: 'antenna', zh: '天线', group: 'critter'},
|
|
39
|
+
];
|
|
40
|
+
export const GROUPS = {critter: '像素生物'};
|
|
41
|
+
|
|
42
|
+
// States it sits down in (feet tucked, a row lower), and states it walks in place.
|
|
43
|
+
const SIT = new Set(['sleeping', 'blocked', 'drowsy', 'bored', 'powering-down', 'sad', 'error']);
|
|
44
|
+
const WALK = new Set(['working', 'running', 'coding', 'controlling', 'sending', 'receiving', 'uploading', 'searching']);
|
|
45
|
+
const DOWN = new Set(['sleeping', 'blocked', 'drowsy', 'sad', 'error', 'powering-down', 'scared']);
|
|
46
|
+
const THINK = new Set(['thinking', 'computing', 'loading', 'orbit', 'radar', 'listening']);
|
|
47
|
+
|
|
48
|
+
// Pixels as one path: each row's runs as rectangles, a little overlap so no seam shows between them.
|
|
49
|
+
function pixels(cells, dy, grow = 0) {
|
|
50
|
+
const rows = new Map();
|
|
51
|
+
for (const [c, r] of cells) { if (!rows.has(r)) rows.set(r, new Set()); rows.get(r).add(c); }
|
|
52
|
+
let d = '';
|
|
53
|
+
for (const [r, set] of rows) {
|
|
54
|
+
const cols = [...set].sort((a, b) => a - b);
|
|
55
|
+
for (let i = 0; i < cols.length;) {
|
|
56
|
+
let j = i; while (j + 1 < cols.length && cols[j + 1] === cols[j] + 1) j++;
|
|
57
|
+
const x = X0 + cols[i] * CELL - grow, y = Y0 + r * CELL + dy - grow, w = (cols[j] - cols[i] + 1) * CELL + 2 * grow, h = CELL + SEAM + 2 * grow;
|
|
58
|
+
d += `M${fixed(x)},${fixed(y)}h${fixed(w)}v${fixed(h)}h${fixed(-w)}Z`;
|
|
59
|
+
i = j + 1;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return d;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
class Critter extends Matrix {
|
|
66
|
+
static shapes = critterShapes;
|
|
67
|
+
tileLayout(ink) {
|
|
68
|
+
this.sit = 0;
|
|
69
|
+
const node = (tag, attrs) => ({layer: 'tile', tag, attrs, parent: null});
|
|
70
|
+
return [node('path', {fill: ink.edge, display: 'none'}), node('path', {fill: ink.body}), node('rect', {width: CELL, height: CELL, fill: ink.bright, display: 'none'})];
|
|
71
|
+
}
|
|
72
|
+
/** Which mood the body is in: {down (ears flop), sit, walk, think}. */
|
|
73
|
+
mood() {
|
|
74
|
+
const state = this.forced ? 'idle' : this.state;
|
|
75
|
+
return {down: DOWN.has(state), sit: SIT.has(state), walk: WALK.has(state), think: THINK.has(state)};
|
|
76
|
+
}
|
|
77
|
+
drawTile(nodes, n, {dt, ink, dim}) {
|
|
78
|
+
const mood = this.mood();
|
|
79
|
+
this.sit = dt === null ? +mood.sit : ease(this.sit, +mood.sit, dt, 8);
|
|
80
|
+
const dy = this.sit * CELL * 0.8;
|
|
81
|
+
// Feet: two pixels each; walking lifts one and then the other; sitting tucks them under.
|
|
82
|
+
let feet = [[1, 10], [2, 10], [6, 10], [7, 10]];
|
|
83
|
+
if (this.sit > 0.5) feet = [];
|
|
84
|
+
else if (mood.walk) feet = floor(this.t * 6) % 2 ? [[1, 10], [2, 10], [6, 9.6], [7, 9.6]] : [[1, 9.6], [2, 9.6], [6, 10], [7, 10]];
|
|
85
|
+
const ears = EARS[this.shape](this.t, mood), body = [...BODY, ...ears, ...feet];
|
|
86
|
+
const [edge, fill, bulb] = [nodes[n++], nodes[n++], nodes[n++]];
|
|
87
|
+
if (ink.edge === 'none') edge.display = 'none';
|
|
88
|
+
else Object.assign(edge, {display: 'inline', d: pixels(body, dy, 0.9), fill: ink.edge});
|
|
89
|
+
Object.assign(fill, {d: pixels(body, dy), fill: ink.body});
|
|
90
|
+
// The antenna's bulb blinks while it thinks.
|
|
91
|
+
if (this.shape !== 'antenna') bulb.display = 'none';
|
|
92
|
+
else {
|
|
93
|
+
const on = mood.think ? floor(this.t * 3) % 2 : 1;
|
|
94
|
+
Object.assign(bulb, {display: 'inline', x: fixed(X0 + 4 * CELL), y: fixed(Y0 + dy), fill: on ? ink.bright : ink.accent, opacity: fixed(0.5 + 0.5 * dim)});
|
|
95
|
+
}
|
|
96
|
+
return n;
|
|
97
|
+
}
|
|
98
|
+
faceLayout(ink, node) {
|
|
99
|
+
return Array.from({length: 25}, () => node('tile', 'rect', {width: fixed(CELL + SEAM), height: fixed(CELL + SEAM), fill: ink.dark, opacity: 0}));
|
|
100
|
+
}
|
|
101
|
+
drawFace(nodes, n, {dt, dim, ink, yaw, pitch, facing}) {
|
|
102
|
+
const {on, blush} = this.lit(yaw, pitch, facing), dy = this.sit * CELL * 0.8;
|
|
103
|
+
for (let i = 0; i < 25; i++) {
|
|
104
|
+
this.level[i] = dt === null ? on[i] : ease(this.level[i], on[i], dt, 26);
|
|
105
|
+
const c = i % 5 + FACE[0], r = floor(i / 5) + FACE[1];
|
|
106
|
+
Object.assign(nodes[n++], {x: fixed(X0 + c * CELL), y: fixed(Y0 + r * CELL + dy), opacity: fixed(max(0, this.level[i]) * dim), fill: blush[i] ? BLUSH : ink.dark});
|
|
107
|
+
}
|
|
108
|
+
return n;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** A critter model. Options as createMatrix's, with `shape` one of critterShapes: identity, hue, chroma, light, dots, edge, shape, eyes, state, progress, size, emphasized. */
|
|
113
|
+
export const createCritter = options => new Critter(options);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Types for '@kodax-ai/botui/themes/critter'.
|
|
2
|
+
|
|
3
|
+
import type {AvatarOptions, ColorName, EyeStyle, ExpressionName, IdentityPool, Theme} from '../../index.js';
|
|
4
|
+
import type {MatrixAvatar, MatrixModel, MatrixTone} from '../matrix/index.js';
|
|
5
|
+
|
|
6
|
+
export type {Avatar, AvatarOptions, ColorName, EyeStyle, ExpressionName, GestureName, IdentityPool, StateName, StateAlias, StateGroup, Theme} from '../../index.js';
|
|
7
|
+
export {setAttention, resolveState, STATES, STATE_GROUPS, ALIASES, COLORS, BIRTH_COLORS, HUES, EYE_STYLES, GESTURES} from '../../index.js';
|
|
8
|
+
|
|
9
|
+
/** Which ears it has. */
|
|
10
|
+
export type CritterShape = 'cat' | 'bear' | 'bunny' | 'antenna';
|
|
11
|
+
/** `shape` is the critter's ears; `signals` and `eyeColor` are ignored, the face shows signals itself. */
|
|
12
|
+
export interface CritterOptions extends Omit<AvatarOptions, 'shape' | 'signals' | 'eyeColor'> { shape?: CritterShape; }
|
|
13
|
+
export interface CritterAvatar extends Omit<MatrixAvatar, 'shape'> { readonly shape: CritterShape; }
|
|
14
|
+
export const CritterAvatar: {new (options?: CritterOptions): CritterAvatar};
|
|
15
|
+
|
|
16
|
+
export const theme: Theme;
|
|
17
|
+
export function createAvatar(options?: CritterOptions): CritterAvatar;
|
|
18
|
+
export function identityFrom(identity: string, pool?: IdentityPool): {shape: CritterShape; color: ColorName; eyes: EyeStyle};
|
|
19
|
+
export const SHAPES: {name: CritterShape; zh: string; group: 'critter'}[];
|
|
20
|
+
export const GROUPS: Record<'critter', string>;
|
|
21
|
+
export const EXPRESSIONS: Record<ExpressionName, Function>;
|
|
22
|
+
|
|
23
|
+
// The pure model: the matrix model with a pixel body and the 5x5 face drawn as pixels.
|
|
24
|
+
export function createCritter(options: MatrixTone & {identity?: string; shape: CritterShape; eyes?: EyeStyle; state?: string; progress?: number | null; size?: number; emphasized?: boolean}): MatrixModel;
|
|
25
|
+
export const critterShapes: readonly CritterShape[];
|
|
26
|
+
export const critterEyes: readonly EyeStyle[];
|
|
27
|
+
export const FACES: Record<ExpressionName, Function>;
|
|
28
|
+
export const SCREENS: Record<string, Function>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// BotUI pixel critter theme: a little pixel-art creature with the matrix face.
|
|
2
|
+
//
|
|
3
|
+
// import {createAvatar} from './themes/critter/index.js';
|
|
4
|
+
// const bot = createAvatar({identity: 'research-bot', size: 36});
|
|
5
|
+
// sidebar.append(bot.el);
|
|
6
|
+
// bot.setState('thinking');
|
|
7
|
+
|
|
8
|
+
import {CritterAvatar} from './avatar.js';
|
|
9
|
+
import {COLORS, EYE_STYLES} from '../../core/identity.js';
|
|
10
|
+
import {STATES} from '../../core/states.js';
|
|
11
|
+
import {registerTheme} from '../../core/registry.js';
|
|
12
|
+
import {GESTURES} from '../../core/motion.js';
|
|
13
|
+
import {FACES} from '../matrix/engine.js';
|
|
14
|
+
import {SHAPES} from './engine.js';
|
|
15
|
+
|
|
16
|
+
export {CritterAvatar, identityFrom} from './avatar.js';
|
|
17
|
+
export {COLORS, BIRTH_COLORS, HUES, EYE_STYLES} from '../../core/identity.js';
|
|
18
|
+
export {STATES, STATE_GROUPS, ALIASES, resolveState} from '../../core/states.js';
|
|
19
|
+
export {setAttention} from '../../core/core.js';
|
|
20
|
+
export {GESTURES} from '../../core/motion.js';
|
|
21
|
+
export {SHAPES, GROUPS, critterShapes, createCritter} from './engine.js';
|
|
22
|
+
export {FACES, SCREENS, matrixEyes as critterEyes} from '../matrix/engine.js';
|
|
23
|
+
/** The expressions, by name: the matrix theme's 5x5 faces, drawn as pixels (see FACES). */
|
|
24
|
+
export const EXPRESSIONS = FACES;
|
|
25
|
+
|
|
26
|
+
/** Create an avatar. Options as MatrixAvatar's. Append `.el` to the page. */
|
|
27
|
+
export function createAvatar(options) { return new CritterAvatar(options); }
|
|
28
|
+
|
|
29
|
+
/** This theme, in the form core/registry.js expects. */
|
|
30
|
+
export const theme = {
|
|
31
|
+
name: 'critter', zh: '像素生物', create: createAvatar,
|
|
32
|
+
catalog: () => ({shapes: SHAPES, colors: Object.keys(COLORS), eyes: Object.keys(EYE_STYLES), states: Object.keys(STATES), gestures: Object.keys(GESTURES), expressions: Object.keys(FACES)}),
|
|
33
|
+
};
|
|
34
|
+
// Importing a theme makes it available to createAvatar({theme}) from the package entry.
|
|
35
|
+
registerTheme(theme);
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# 手绘 doodle
|
|
2
|
+
|
|
3
|
+
用墨线手绘的 Bot:轮廓描两遍(一道实线,一道更淡、收笔时越过起点的线),颜色像马克笔一样涂得稍微出了线,右下角几笔排线做阴影。线条会“沸腾”:每秒重画八次,每次抖得不一样,就像手绘动画。眼睛和立体家族同形,每种眼神配一张嘴,害羞时脸上划几道红。
|
|
4
|
+
|
|
5
|
+
来自 avatar-lab 的草图方向 O(手绘),2026-11-28 做成主题。
|
|
6
|
+
|
|
7
|
+
## 用法
|
|
8
|
+
|
|
9
|
+
```js
|
|
10
|
+
import {createAvatar} from '@kodax-ai/botui/themes/doodle'; // 或相对路径 ./themes/doodle/index.js
|
|
11
|
+
|
|
12
|
+
const bot = createAvatar({identity: 'research-bot', size: 36});
|
|
13
|
+
sidebar.append(bot.el);
|
|
14
|
+
bot.setState('thinking');
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
从总入口用:先 `import '@kodax-ai/botui/themes/doodle'`,再 `createAvatar({theme: 'doodle', ...})`。自定义元素:同样先加载主题脚本,再写 `<bot-avatar theme="doodle" identity="research-bot"></bot-avatar>`。
|
|
18
|
+
|
|
19
|
+
## 与点阵的关系
|
|
20
|
+
|
|
21
|
+
外形(圆角方、圆、六边形)、颜色、动作、记号、粒子、交互、水印都和 [点阵](../matrix/README.md) 一样,选项和方法也完全相同;同一个 Bot ID 在两个主题里是同一个外形、颜色和眼型。不同的是:
|
|
22
|
+
|
|
23
|
+
| 项 | 手绘 |
|
|
24
|
+
|---|---|
|
|
25
|
+
| 身体 | 三种外形都画成抖动的墨线,填色偏移出线 |
|
|
26
|
+
| 眼睛 | 用立体家族的 `eyeShape`:21 种眼神、三种眼型同形,线条一样会抖 |
|
|
27
|
+
| 嘴(`MOUTHS`) | 每种眼神一张:开心上弯、难过下弯、生气锯齿、惊讶一个圈、困一条平线……说话的状态(输出、听写、哼歌、大笑、打招呼)嘴一张一合 |
|
|
28
|
+
| 腮红 | 三道短斜线 |
|
|
29
|
+
| 信号状态 | 屏幕不放图案,靠眼神、嘴和右上角记号表达;进度状态外圈有一道铅笔画的弧 |
|
|
30
|
+
| 沸腾 | 抖动由帧号的哈希决定,每 1/8 秒换一次;静止帧(`static`)不抖 |
|
|
31
|
+
|
|
32
|
+
## 纯模型
|
|
33
|
+
|
|
34
|
+
`createDoodle(options)` 与 `createMatrix` 用法相同。不碰 DOM、不用时钟和 `Math.random`,同样的输入永远得到同样的帧。
|
|
35
|
+
|
|
36
|
+
## 文件
|
|
37
|
+
|
|
38
|
+
| 文件 | 内容 |
|
|
39
|
+
|---|---|
|
|
40
|
+
| `index.js` | 入口:`createAvatar`、`theme` 和各种表 |
|
|
41
|
+
| `avatar.js` | `DoodleAvatar`:继承点阵的 `MatrixAvatar`,只换模型 |
|
|
42
|
+
| `engine.js` | 手绘:抖动的轮廓、排线、眼睛、嘴表 `MOUTHS`、进度弧 |
|
|
43
|
+
| `playground.html` | 试玩页(共用 `../solids/playground.js`) |
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import {MatrixAvatar} from '../matrix/avatar.js';
|
|
2
|
+
import {createDoodle} from './engine.js';
|
|
3
|
+
|
|
4
|
+
export {identityFrom} from '../matrix/avatar.js';
|
|
5
|
+
|
|
6
|
+
/** The doodle avatar: the matrix avatar drawn by hand, in boiling ink lines. Options and methods as MatrixAvatar's. */
|
|
7
|
+
export class DoodleAvatar extends MatrixAvatar {
|
|
8
|
+
static className = 'botui-doodle';
|
|
9
|
+
createModel(options) { return createDoodle(options); }
|
|
10
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
// The doodle theme's model: the Bot drawn by hand, in ink, with marker colour.
|
|
2
|
+
//
|
|
3
|
+
// The outline is drawn twice in ink, and the colour is filled in a little off
|
|
4
|
+
// the lines, like a marker. The lines boil: every eighth of a second they are
|
|
5
|
+
// redrawn with a slightly different wobble, the way hand-drawn animation does.
|
|
6
|
+
// The eyes are the solids' eyes, every expression and eye style, drawn in the
|
|
7
|
+
// same wobbly ink, with a mouth for each expression and a scribble of blush.
|
|
8
|
+
//
|
|
9
|
+
// Everything else (outline shapes, motion, marks, particles, halo, handling) is
|
|
10
|
+
// the matrix model's. Pure, like it: no DOM, no clock, no Math.random; the
|
|
11
|
+
// wobble comes from a hash of the frame number.
|
|
12
|
+
// Sketched in avatar-lab as direction O (手绘), made a theme on 2026-11-28.
|
|
13
|
+
|
|
14
|
+
import {Matrix} from '../matrix/engine.js';
|
|
15
|
+
import {eyeShape} from '../solids/face.js';
|
|
16
|
+
import {EYE_STYLES} from '../../core/identity.js';
|
|
17
|
+
import {TAU, clamp} from '../../core/core.js';
|
|
18
|
+
|
|
19
|
+
const {sin, cos, abs, max, floor, pow} = Math;
|
|
20
|
+
const fixed = v => v.toFixed(2);
|
|
21
|
+
const E = 42, R = 36, BOIL = 8, RING = 44, BLUSH = 'oklch(0.68 0.17 15)', HEART = 'oklch(0.6 0.22 15)';
|
|
22
|
+
const noise = n => { const s = sin(n * 12.9898 + 78.233) * 43758.5453; return s - floor(s) - 0.5; };
|
|
23
|
+
|
|
24
|
+
/** The doodle's eyes are the solids': dot (圆点), bar (竖条), tall (长条). */
|
|
25
|
+
export const doodleEyes = Object.freeze(Object.keys(EYE_STYLES));
|
|
26
|
+
|
|
27
|
+
// The outlines as points, so they can wobble: the matrix theme's three shapes.
|
|
28
|
+
const ring = (n, at) => Array.from({length: n}, (_, i) => at(i / n * TAU));
|
|
29
|
+
const OUTLINES = {
|
|
30
|
+
circle: ring(30, a => [50 + R * cos(a), 50 + R * sin(a)]),
|
|
31
|
+
squircle: ring(36, a => { const p = 4.5, r = pow(pow(abs(cos(a)), p) + pow(abs(sin(a)), p), -1 / p) / pow(2, 0.5 - 1 / p) * (R + 2); return [50 + r * cos(a), 50 + r * sin(a)]; }),
|
|
32
|
+
hex: ring(36, a => { const k = floor((a + TAU / 12) / (TAU / 6)), mid = k * TAU / 6, r = (R + 3) * cos(TAU / 12) / cos(a - mid); return [50 + r * cos(a), 50 + r * sin(a)]; }),
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// A smooth line through points (closed: loops back to the start).
|
|
36
|
+
function smooth(points, closed) {
|
|
37
|
+
const mid = (a, b) => [(a[0] + b[0]) / 2, (a[1] + b[1]) / 2], pt = p => fixed(p[0]) + ',' + fixed(p[1]);
|
|
38
|
+
if (!closed) {
|
|
39
|
+
if (points.length < 3) return points.map((p, i) => (i ? 'L' : 'M') + pt(p)).join('');
|
|
40
|
+
let d = 'M' + pt(points[0]);
|
|
41
|
+
for (let i = 1; i < points.length - 1; i++) d += 'Q' + pt(points[i]) + ' ' + pt(mid(points[i], points[i + 1]));
|
|
42
|
+
return d + 'L' + pt(points[points.length - 1]);
|
|
43
|
+
}
|
|
44
|
+
const n = points.length;
|
|
45
|
+
let d = 'M' + pt(mid(points[n - 1], points[0]));
|
|
46
|
+
for (let i = 0; i < n; i++) d += 'Q' + pt(points[i]) + ' ' + pt(mid(points[i], points[(i + 1) % n]));
|
|
47
|
+
return d + 'Z';
|
|
48
|
+
}
|
|
49
|
+
const wobble = (points, amount, seed) => points.map(([x, y], i) => [x + noise(seed + i * 1.7) * amount, y + noise(seed + i * 2.3 + 50) * amount]);
|
|
50
|
+
|
|
51
|
+
/** A mouth for each expression, as lines in the face's units (x right, y down), or null for none. */
|
|
52
|
+
const curve = (w, bend, y = 0.36) => [[-w, y - bend], [0, y + bend], [w, y - bend]];
|
|
53
|
+
const oval = (rx, ry, y = 0.38) => ring(10, a => [rx * cos(a), y + ry * sin(a)]).concat([[rx, y]]);
|
|
54
|
+
export const MOUTHS = {
|
|
55
|
+
neutral: () => [curve(0.08, 0.025)],
|
|
56
|
+
wide: () => [oval(0.05, 0.06)],
|
|
57
|
+
happy: () => [curve(0.15, 0.07)],
|
|
58
|
+
closed: () => [curve(0.07, 0)],
|
|
59
|
+
sleep: () => [oval(0.035, 0.04)],
|
|
60
|
+
squint: () => [curve(0.17, 0.09)],
|
|
61
|
+
sad: () => [curve(0.12, -0.05, 0.4)],
|
|
62
|
+
focus: () => [[[-0.06, 0.37], [0.06, 0.37]]],
|
|
63
|
+
angry: () => [[[-0.12, 0.4], [-0.06, 0.36], [0, 0.4], [0.06, 0.36], [0.12, 0.4]]],
|
|
64
|
+
calm: () => [curve(0.1, 0.04)],
|
|
65
|
+
sleepy: () => [[[-0.07, 0.38], [0.07, 0.37]]],
|
|
66
|
+
shy: () => [curve(0.05, 0.02)],
|
|
67
|
+
inspecting: () => [[[-0.02, 0.37], [0.1, 0.35]]],
|
|
68
|
+
confused: () => [[[-0.1, 0.4], [-0.03, 0.36], [0.03, 0.4], [0.1, 0.36]]],
|
|
69
|
+
wink: () => [[[-0.1, 0.36], [0.02, 0.41], [0.12, 0.33]]],
|
|
70
|
+
skeptic: () => [[[-0.1, 0.39], [0.1, 0.36]]],
|
|
71
|
+
cross: () => [[[-0.1, 0.38], [-0.04, 0.35], [0.02, 0.4], [0.1, 0.37]]],
|
|
72
|
+
surprised: () => [oval(0.06, 0.075)],
|
|
73
|
+
dizzy: () => [[[-0.12, 0.38], [-0.06, 0.34], [0, 0.39], [0.06, 0.34], [0.12, 0.38]]],
|
|
74
|
+
love: () => [curve(0.13, 0.06)],
|
|
75
|
+
sparkle: () => [curve(0.15, 0.08), [[-0.15, 0.29], [0.15, 0.29]]],
|
|
76
|
+
};
|
|
77
|
+
// States it talks in: the mouth opens and closes.
|
|
78
|
+
const TALK = {streaming: 9, dictating: 7, humming: 4, laughing: 11, greeting: 6};
|
|
79
|
+
|
|
80
|
+
class Doodle extends Matrix {
|
|
81
|
+
tileLayout(ink, node) {
|
|
82
|
+
return [
|
|
83
|
+
node('tile', 'path', {fill: ink.body, opacity: 0.92}),
|
|
84
|
+
...[0, 1, 2].map(() => node('tile', 'path', {fill: 'none', stroke: ink.dark, 'stroke-linecap': 'round', 'stroke-width': 1.4, opacity: 0.45})),
|
|
85
|
+
node('tile', 'path', {fill: 'none', stroke: ink.dark, 'stroke-linecap': 'round', 'stroke-linejoin': 'round', 'stroke-width': 2.8}),
|
|
86
|
+
node('tile', 'path', {fill: 'none', stroke: ink.dark, 'stroke-linecap': 'round', 'stroke-linejoin': 'round', 'stroke-width': 1.3, opacity: 0.55}),
|
|
87
|
+
node('tile', 'path', {fill: 'none', 'stroke-linecap': 'round', 'stroke-width': 3}),
|
|
88
|
+
];
|
|
89
|
+
}
|
|
90
|
+
/** The wobble seed for this frame: the lines are redrawn BOIL times a second. */
|
|
91
|
+
get seed() { return floor(this.t * BOIL) * 97; }
|
|
92
|
+
drawTile(nodes, n, {ink, dim}) {
|
|
93
|
+
const s = this.seed, base = OUTLINES[this.shape] || OUTLINES.circle;
|
|
94
|
+
// Marker colour a little off the lines; three hatch strokes of shade low on the right.
|
|
95
|
+
Object.assign(nodes[n++], {d: smooth(wobble(base.map(([x, y]) => [50 + (x - 50) * 0.95 + 2.2, 50 + (y - 50) * 0.95 + 1.6]), 2.2, s + 7), true), fill: ink.body});
|
|
96
|
+
for (let i = 0; i < 3; i++) {
|
|
97
|
+
const a = 0.35 + i * 0.22, r1 = R - 13, r2 = R - 4, j = noise(s + 300 + i) * 1.6;
|
|
98
|
+
Object.assign(nodes[n++], {d: `M${fixed(50 + r1 * cos(a) + j)},${fixed(50 + r1 * sin(a))}L${fixed(50 + r2 * cos(a - 0.28))},${fixed(50 + r2 * sin(a - 0.28) + j)}`, stroke: ink.dark, opacity: fixed(0.4 * dim)});
|
|
99
|
+
}
|
|
100
|
+
// The outline twice: a firm line, then a lighter one that overshoots where the pen started.
|
|
101
|
+
Object.assign(nodes[n++], {d: smooth(wobble(base, 1.6, s), true), stroke: ink.dark, opacity: fixed(0.5 + 0.5 * dim)});
|
|
102
|
+
const second = wobble(base, 2.6, s + 31), over = [...second, ...second.slice(0, 4)].map(([x, y]) => [50 + (x - 50) * 1.02, 50 + (y - 50) * 1.02]);
|
|
103
|
+
Object.assign(nodes[n++], {d: smooth(over, false), stroke: ink.dark, opacity: fixed(0.55 * dim)});
|
|
104
|
+
// The progress ring: a pencil arc around it.
|
|
105
|
+
const node = nodes[n++], u = this.state === 'progress' ? clamp(this.progress ?? (this.t * 0.22) % 1, 0, 1) : 0;
|
|
106
|
+
if (u <= 0.001) Object.assign(node, {d: '', opacity: 0});
|
|
107
|
+
else {
|
|
108
|
+
const steps = max(2, floor(u * 32)), pts = Array.from({length: steps + 1}, (_, i) => { const a = -TAU / 4 + u * TAU * i / steps; return [50 + RING * cos(a), 50 + RING * sin(a)]; });
|
|
109
|
+
Object.assign(node, {d: smooth(wobble(pts, 1.2, s + 77), false), stroke: ink.accent, opacity: 1});
|
|
110
|
+
}
|
|
111
|
+
return n;
|
|
112
|
+
}
|
|
113
|
+
faceLayout(ink, node) {
|
|
114
|
+
const line = {fill: 'none', 'stroke-linecap': 'round', 'stroke-linejoin': 'round', stroke: ink.dark};
|
|
115
|
+
return [
|
|
116
|
+
...[-1, 1].map(() => node('tile', 'path', {fill: 'none', stroke: BLUSH, 'stroke-linecap': 'round', 'stroke-width': 1.5, opacity: 0})),
|
|
117
|
+
...[-1, 1].map(() => node('tile', 'path', line)),
|
|
118
|
+
node('tile', 'path', {...line, 'stroke-width': 2.4}),
|
|
119
|
+
];
|
|
120
|
+
}
|
|
121
|
+
drawFace(nodes, n, {ink, dim, yaw, pitch, facing}) {
|
|
122
|
+
const p = this.p, s = this.seed, style = EYE_STYLES[this.eyes] || EYE_STYLES.tall, k = this.size < 40 ? 1.15 : 1, fade = 0.35 + 0.65 * dim;
|
|
123
|
+
const ox = clamp((-sin(yaw) * 1.5 + this.gx * 5) * 7, -9, 9), oy = clamp((pitch * 1.6 + this.gy * 5) * 5, -6, 6);
|
|
124
|
+
const draw = (lines, cx, cy, amount, seed) => lines.map((line, i) => smooth(wobble(line.map(([x, y]) => [cx + x * E * k, cy + y * E * k]), amount, seed + i * 13), false)).join('');
|
|
125
|
+
// Blush: three short slashes under each eye.
|
|
126
|
+
for (const side of [-1, 1]) {
|
|
127
|
+
const cx = 50 + side * 22 + ox, cy = 58 + oy, on = facing ? 0.9 * p.blush : 0;
|
|
128
|
+
const d = on > 0.02 ? [0, 1, 2].map(i => `M${fixed(cx - 4 + i * 3.4 + noise(s + side * 9 + i))},${fixed(cy + 2)}l2.4,-4`).join('') : '';
|
|
129
|
+
Object.assign(nodes[n++], {d, opacity: fixed(on)});
|
|
130
|
+
}
|
|
131
|
+
for (const side of [-1, 1]) {
|
|
132
|
+
const node = nodes[n++];
|
|
133
|
+
if (!facing) { Object.assign(node, {d: '', opacity: 0}); continue; }
|
|
134
|
+
const eye = eyeShape(this.shown, side, style, p.open), cx = 50 + side * style.gap * E * k + ox, cy = 45 + oy;
|
|
135
|
+
// A filled eye (love, sparkle) is coloured in.
|
|
136
|
+
const colour = this.shown === 'love' ? HEART : ink.dark;
|
|
137
|
+
Object.assign(node, {d: draw(eye.lines, cx, cy, 0.9, s + side * 40) + (eye.fill ? 'Z' : ''), 'stroke-width': fixed(max(2.2, eye.w * E * k * 0.75)), stroke: colour, fill: eye.fill ? colour : 'none', opacity: fixed(fade)});
|
|
138
|
+
}
|
|
139
|
+
// The mouth: the expression's, or opening and closing while it talks.
|
|
140
|
+
const talk = !this.forced && facing ? TALK[this.state] : 0, mouth = nodes[n++];
|
|
141
|
+
let lines = facing ? (MOUTHS[this.shown] || MOUTHS.neutral)() : [];
|
|
142
|
+
if (talk) { const open = abs(sin(this.t * talk)) * (0.6 + 0.4 * abs(sin(this.t * talk * 0.37))); lines = [oval(0.07, 0.01 + 0.07 * open)]; }
|
|
143
|
+
Object.assign(mouth, {d: lines.length ? draw(lines, 50 + ox, 50 + oy, 0.7, s + 200) : '', opacity: fixed(fade)});
|
|
144
|
+
return n;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** A doodle model. Options as createMatrix's: identity, hue, chroma, light, dots, edge, shape, eyes, state, progress, size, emphasized. */
|
|
149
|
+
export const createDoodle = options => new Doodle(options);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// Types for '@kodax-ai/botui/themes/doodle'.
|
|
2
|
+
|
|
3
|
+
import type {ColorName, EyeStyle, ExpressionName, IdentityPool, Theme} from '../../index.js';
|
|
4
|
+
import type {MatrixAvatar, MatrixOptions, MatrixShape, MatrixModel, MatrixTone} from '../matrix/index.js';
|
|
5
|
+
|
|
6
|
+
export type {Avatar, AvatarOptions, ColorName, EyeStyle, ExpressionName, GestureName, IdentityPool, StateName, StateAlias, StateGroup, Theme} from '../../index.js';
|
|
7
|
+
export type {MatrixOptions as DoodleOptions, MatrixShape as DoodleShape} from '../matrix/index.js';
|
|
8
|
+
export {setAttention, resolveState, STATES, STATE_GROUPS, ALIASES, COLORS, BIRTH_COLORS, HUES, EYE_STYLES, GESTURES} from '../../index.js';
|
|
9
|
+
export {SHAPES, GROUPS} from '../matrix/index.js';
|
|
10
|
+
|
|
11
|
+
export interface DoodleAvatar extends MatrixAvatar {}
|
|
12
|
+
export const DoodleAvatar: {new (options?: MatrixOptions): DoodleAvatar};
|
|
13
|
+
|
|
14
|
+
export const theme: Theme;
|
|
15
|
+
export function createAvatar(options?: MatrixOptions): DoodleAvatar;
|
|
16
|
+
export function identityFrom(identity: string, pool?: IdentityPool): {shape: MatrixShape; color: ColorName; eyes: EyeStyle};
|
|
17
|
+
export const EXPRESSIONS: Record<ExpressionName, Function>;
|
|
18
|
+
|
|
19
|
+
// The pure model: the matrix model with a hand-drawn body, eyes and mouth in boiling ink lines.
|
|
20
|
+
export function createDoodle(options: MatrixTone & {identity?: string; shape: MatrixShape; eyes?: EyeStyle; state?: string; progress?: number | null; size?: number; emphasized?: boolean}): MatrixModel;
|
|
21
|
+
export const doodleShapes: readonly MatrixShape[];
|
|
22
|
+
export const doodleEyes: readonly EyeStyle[];
|
|
23
|
+
export const FACES: Record<ExpressionName, Function>;
|
|
24
|
+
export const MOUTHS: Record<ExpressionName, () => [number, number][][]>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// BotUI doodle theme: the Bot drawn by hand, in ink and marker.
|
|
2
|
+
//
|
|
3
|
+
// import {createAvatar} from './themes/doodle/index.js';
|
|
4
|
+
// const bot = createAvatar({identity: 'research-bot', size: 36});
|
|
5
|
+
// sidebar.append(bot.el);
|
|
6
|
+
// bot.setState('thinking');
|
|
7
|
+
|
|
8
|
+
import {DoodleAvatar} from './avatar.js';
|
|
9
|
+
import {COLORS, EYE_STYLES} from '../../core/identity.js';
|
|
10
|
+
import {STATES} from '../../core/states.js';
|
|
11
|
+
import {registerTheme} from '../../core/registry.js';
|
|
12
|
+
import {GESTURES} from '../../core/motion.js';
|
|
13
|
+
import {EXPRESSIONS as FACES} from '../solids/face.js';
|
|
14
|
+
import {SHAPES} from '../matrix/engine.js';
|
|
15
|
+
|
|
16
|
+
export {DoodleAvatar, identityFrom} from './avatar.js';
|
|
17
|
+
export {COLORS, BIRTH_COLORS, HUES, EYE_STYLES} from '../../core/identity.js';
|
|
18
|
+
export {STATES, STATE_GROUPS, ALIASES, resolveState} from '../../core/states.js';
|
|
19
|
+
export {setAttention} from '../../core/core.js';
|
|
20
|
+
export {GESTURES} from '../../core/motion.js';
|
|
21
|
+
export {SHAPES, GROUPS, matrixShapes as doodleShapes} from '../matrix/engine.js';
|
|
22
|
+
export {createDoodle, doodleEyes, MOUTHS} from './engine.js';
|
|
23
|
+
export {EXPRESSIONS as FACES} from '../solids/face.js';
|
|
24
|
+
/** The expressions, by name: the solids' eyes, drawn by hand, with a mouth each (see FACES and MOUTHS). */
|
|
25
|
+
export const EXPRESSIONS = FACES;
|
|
26
|
+
|
|
27
|
+
/** Create an avatar. Options as MatrixAvatar's. Append `.el` to the page. */
|
|
28
|
+
export function createAvatar(options) { return new DoodleAvatar(options); }
|
|
29
|
+
|
|
30
|
+
/** This theme, in the form core/registry.js expects. */
|
|
31
|
+
export const theme = {
|
|
32
|
+
name: 'doodle', zh: '手绘', create: createAvatar,
|
|
33
|
+
catalog: () => ({shapes: SHAPES, colors: Object.keys(COLORS), eyes: Object.keys(EYE_STYLES), states: Object.keys(STATES), gestures: Object.keys(GESTURES), expressions: Object.keys(FACES)}),
|
|
34
|
+
};
|
|
35
|
+
// Importing a theme makes it available to createAvatar({theme}) from the package entry.
|
|
36
|
+
registerTheme(theme);
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# 活点 dots
|
|
2
|
+
|
|
3
|
+
五颗带弹簧的点,画在点阵主题的彩色方块上。每颗点是一个能移动、拉长、旋转的胶囊,被弹簧拉向目标位置,所以每次换表情都是一次物理运动:眼睛拉长成竖条,分裂成对勾,合并成一颗点。用不到的点缩进旁边一颗看得见的点里,之后再从里面分裂出来。
|
|
4
|
+
|
|
5
|
+
来自 avatar-lab 的草图方向 H(活点),2026-11-28 做成主题。
|
|
6
|
+
|
|
7
|
+
## 用法
|
|
8
|
+
|
|
9
|
+
```js
|
|
10
|
+
import {createAvatar} from '@kodax-ai/botui/themes/dots'; // 或相对路径 ./themes/dots/index.js
|
|
11
|
+
|
|
12
|
+
const bot = createAvatar({identity: 'research-bot', size: 36});
|
|
13
|
+
sidebar.append(bot.el);
|
|
14
|
+
bot.setState('thinking');
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
从总入口用:先 `import '@kodax-ai/botui/themes/dots'`,再 `createAvatar({theme: 'dots', ...})`。自定义元素:同样先加载主题脚本,再写 `<bot-avatar theme="dots" identity="research-bot"></bot-avatar>`。
|
|
18
|
+
|
|
19
|
+
## 与点阵的关系
|
|
20
|
+
|
|
21
|
+
方块、外形(圆角方、圆、六边形)、颜色、动作、记号、粒子、交互、水印都和 [点阵](../matrix/README.md) 一样,选项和方法也完全相同;同一个 Bot ID 在两个主题里是同一个外形、颜色和眼型。不同的只有脸:
|
|
22
|
+
|
|
23
|
+
| 项 | 活点 |
|
|
24
|
+
|---|---|
|
|
25
|
+
| 眼型 | `dot` 圆点、`bar` 竖条、`tall` 长条,是一颗点的三种比例 |
|
|
26
|
+
| 眼神 | 21 种都有,由 1–2 颗点拼成:`happy` 是两笔 ^,`squint` 是 > <,`love` 是两颗红心,`sparkle` 是来回转的十字 |
|
|
27
|
+
| 换表情 | 立即开始变形,不像点阵那样藏在一次眨眼后面 |
|
|
28
|
+
| 信号状态 | 点拼成图案:思考三点弹跳、输出五根音柱、完成对勾、进度条、雷达、上下行箭头、书写、感叹号等 |
|
|
29
|
+
| 戳一下 | 除了点阵的反应,五颗点还会被弹散再弹回来 |
|
|
30
|
+
|
|
31
|
+
## 纯模型
|
|
32
|
+
|
|
33
|
+
`createDots(options)` 与 `createMatrix` 用法相同,只是脸换成五颗点。不碰 DOM、不用时钟和 `Math.random`,同样的输入永远得到同样的帧。
|
|
34
|
+
|
|
35
|
+
## 文件
|
|
36
|
+
|
|
37
|
+
| 文件 | 内容 |
|
|
38
|
+
|---|---|
|
|
39
|
+
| `index.js` | 入口:`createAvatar`、`theme` 和各种表 |
|
|
40
|
+
| `avatar.js` | `DotsAvatar`:继承点阵的 `MatrixAvatar`,只换模型 |
|
|
41
|
+
| `engine.js` | 五颗点:眼神表 `FACES`、屏幕表 `SCREENS`、弹簧 |
|
|
42
|
+
| `playground.html` | 试玩页(共用 `../solids/playground.js`) |
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// The live dots theme: five dots on springs, on the matrix theme's coloured tile.
|
|
2
|
+
//
|
|
3
|
+
// Everything but the face is the matrix theme's: options, methods, interaction,
|
|
4
|
+
// watermark, identity. A Bot has the same tile outline, colour and eye style here
|
|
5
|
+
// as in the matrix, and the same colour and eye style as in the solids.
|
|
6
|
+
|
|
7
|
+
import {MatrixAvatar} from '../matrix/avatar.js';
|
|
8
|
+
import {createDots} from './engine.js';
|
|
9
|
+
|
|
10
|
+
export {identityFrom} from '../matrix/avatar.js';
|
|
11
|
+
|
|
12
|
+
export class DotsAvatar extends MatrixAvatar {
|
|
13
|
+
static className = 'botui-dots';
|
|
14
|
+
createModel(options) { return createDots(options); }
|
|
15
|
+
}
|