Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# AGENTS.md — BotPixel

Two packages: `packages/morph` (`@botharness/pixel-morph`, generic pixel morph) and `packages/avatar` (`@botharness/pixel-avatar`, the avatar generator and symbols). Both are pure TypeScript with no third-party runtime dependencies; `pixel-avatar` depends only on `pixel-morph` (for `PixelCell` and attribute escaping).
Three packages: `packages/morph` (`@botharness/pixel-morph`, generic pixel morph), `packages/avatar` (`@botharness/pixel-avatar`, the avatar generator and symbols) and `packages/banner` (`@botharness/pixel-banner`, seeded 3:1 nature banners). All are pure TypeScript with no third-party runtime dependencies; `pixel-avatar` depends only on `pixel-morph` (for `PixelCell` and attribute escaping), and `pixel-banner` depends on nothing.

## Commands

Expand All @@ -12,7 +12,7 @@ pnpm build

## Rules

- Output compatibility is the contract. `packages/avatar/test/fixtures/botharness-golden.json` holds hashes of BotHarness's output for every option, preset, seed, symbol and morph. Do not regenerate it to make a change pass; a visual change to existing options needs a new `rigVersion`/`assetVersion`.
- Output compatibility is the contract. `packages/avatar/test/fixtures/botharness-golden.json` holds hashes of BotHarness's output for every option, preset, seed, symbol and morph. Do not regenerate it to make a change pass; a visual change to existing options needs a new `rigVersion`/`assetVersion`. `packages/banner/test/fixtures/banner-golden.json` does the same for banners: a saved `{ scene, seed }` must keep its pixels, so a visual change needs a new scene name.
- Keep `pixel-morph` free of avatar concepts.
- Tool-to-symbol mapping belongs to the host app, not to this repo.

Expand All @@ -21,7 +21,7 @@ pnpm build
```bash
bash scripts/npm-token.sh # store the npm publish token (gitignored, mode 600)
pnpm release # build + verify, then print what it would publish
pnpm release -- --yes # publish pixel-morph, then pixel-avatar
pnpm release -- --yes # publish pixel-morph, pixel-avatar, then pixel-banner
```

Same flow as BotUI: a granular npm token with _Read and write_ + _Bypass 2FA_, scoped to `@botharness` (a token limited to package names cannot create new packages). To reuse BotUI's saved token, point at it: `NPM_TOKEN_FILE=../BotUI/npm_release.token pnpm release -- --yes`.
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased

- `@botharness/pixel-banner` 0.1.0 (new): seeded 3:1 pixel nature banners for profile headers in ten scenes. A `{ scene, seed }` recipe renders 150×50 pixels and scales them ×10 to exactly 1500×500 RGBA with no smoothing; `seededBannerRecipe(name)` gives the same banner for the same name, and a golden test locks every scene's output.
- `@botharness/pixel-avatar` 0.2.0: opt-in `mouthLayers` adds saved/closed/half-open/open speech features to every head turn. Existing recipes, static snapshots and default golden output remain unchanged; text pacing stays with the consumer.
- `@botharness/pixel-morph`: one morph that throws no longer stops the shared animation loop for the others, and a morph started from inside a frame no longer starts a second frame chain.

Expand Down
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

# BotPixel

Pixel art that changes shape. Two small, dependency-free packages from [BotHarness](https://github.com/BotHarness/BotHarness):
Pixel art that changes shape. Three small, dependency-free packages from [BotHarness](https://github.com/BotHarness/BotHarness):

| Package | What it does |
| --------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [`@botharness/pixel-morph`](packages/morph) | Morphs any set of pixels into any other: every pixel hops along a short arc to a partner and snaps to the grid. Works on plain `{ x, y, c }` cells, so it is not tied to avatars. |
| [`@botharness/pixel-avatar`](packages/avatar) | Seeded, editable 32×32 chibi pixel avatars, plus 16 state symbols (thinking, reading, editing, searching…) the avatar can morph into while an agent works. |
| [`@botharness/pixel-banner`](packages/banner) | Seeded 3:1 pixel nature banners for profile headers in ten scenes (spring, summer, autumn, winter, sea, mountain, desert, forest, night sky, space), 1500×500 RGBA. |

```bash
npm install @botharness/pixel-avatar
Expand Down Expand Up @@ -57,17 +58,24 @@ A recipe is plain JSON (`head`, `hair`, `eyes`, `outfit`, `accessory`, colours

Hosts add their own state symbols with `symbolArtCells(rows, color)`, which draws 24×24 character art (`A` body, `H` highlight) in the built-in style.

## Profile banners

`seededBannerRecipe(name)` picks a scene and a seed; `pixelBannerImage(recipe)` returns 1500×500 RGBA pixels, scaled ×10 from a 150×50 drawing with no smoothing. Every scene, on a light and a dark page:

<p align="center"><img src="assets/banner-scenes-light.png" alt="All ten banner scenes on a light page" width="49%"> <img src="assets/banner-scenes-dark.png" alt="All ten banner scenes on a dark page" width="49%"></p>

## Contributing

```bash
pnpm install
pnpm verify # format, lint, typecheck, test
pnpm build
pnpm assets # re-render the README banner and GIFs (needs ffmpeg)
pnpm assets # re-render the README banner, GIFs and banner scenes (needs ffmpeg)
```

- New eyes, brows, mouths and symbols are character art: add rows, and the diff shows the picture.
- `packages/avatar/test/fixtures/botharness-golden.json` locks the output of every existing option and seed. Saved avatars must not change, so a PR that breaks it needs a new recipe version, not a new fixture.
- `packages/banner/test/fixtures/banner-golden.json` does the same for every banner scene.

## License

Expand Down
9 changes: 8 additions & 1 deletion README.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,23 @@

# BotPixel

会变形的像素画。来自 [BotHarness](https://github.com/BotHarness/BotHarness) 的两个零依赖小包:
会变形的像素画。来自 [BotHarness](https://github.com/BotHarness/BotHarness) 的三个零依赖小包:

- **`@botharness/pixel-morph`**:任意一组像素变成另一组像素。每个像素按极角配对,沿小弧线跳到目标,并始终对齐网格。只认 `{ x, y, c }`,不限于头像。
- **`@botharness/pixel-avatar`**:按名字生成、可编辑的 32×32 Q 版像素头像,加上 16 个状态符号(思考、读文件、编辑、搜索……),Agent 工作时头像可以变形成这些符号。
- **`@botharness/pixel-banner`**:按名字生成的 3:1 像素自然风景横幅,用作资料页头图。共十个场景(春、夏、秋、冬、海、山、沙漠、森林、星空、太空),输出 1500×500 RGBA。

<p align="center"><img src="assets/morph-turn.gif" alt="头像变形成各个工具的符号再变回来" width="288"></p>
<p align="center"><img src="assets/morph-crew.gif" alt="多个头像各自变形成不同工具的符号" width="100%"></p>

用法、原理和贡献方式见 [README.md](README.md)。

## 资料页横幅

`seededBannerRecipe(name)` 按名字选出场景和种子;`pixelBannerImage(recipe)` 返回 1500×500 的 RGBA 像素,由 150×50 的原图整数放大 10 倍,不做平滑。全部场景在浅色和深色页面上的效果:

<p align="center"><img src="assets/banner-scenes-light.png" alt="浅色页面上的十个横幅场景" width="49%"> <img src="assets/banner-scenes-dark.png" alt="深色页面上的十个横幅场景" width="49%"></p>

## 说话嘴型

给 `pixelAvatarSvg` 或 `pixelFigure` 传入 `{ mouthLayers: true }`,即可按需生成嘴型图层。每个转头角度都包含四组 `[data-avatar-mouth]`:`saved`(原本的表情)、`closed`(闭合)、`half-open`(半开)、`open`(张开)。每个角度同时只显示一个状态;说话结束或取消时恢复 `saved`。图层保留共享的眉毛、鼻子和脸颊,以维持原有像素绘制顺序;眼神、眨眼、眼镜和转头保持独立。文本节奏与减少动效策略由使用方负责。不启用该选项时,现有输出逐字节保持不变,配方与已保存的快照不变。
Expand Down
Binary file added assets/banner-scenes-dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/banner-scenes-light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"name": "botpixel",
"version": "0.0.0",
"private": true,
"description": "BotPixel — a pixel morph engine and a pixel avatar kit for agent products",
"description": "BotPixel — a pixel morph engine, a pixel avatar kit and pixel banners for agent products",
"type": "module",
"scripts": {
"build": "pnpm -r --filter \"./packages/*\" build",
"typecheck": "tsc --noEmit -p packages/morph && tsc --noEmit -p packages/avatar",
"typecheck": "tsc --noEmit -p packages/morph && tsc --noEmit -p packages/avatar && tsc --noEmit -p packages/banner",
"lint": "oxlint",
"lint:fix": "oxlint --fix",
"format": "oxfmt --write .",
Expand Down
21 changes: 21 additions & 0 deletions packages/banner/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2026 BotHarness

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
26 changes: 26 additions & 0 deletions packages/banner/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# @botharness/pixel-banner

Seeded pixel-art nature banners in ten scenes, for profile headers. Each banner is drawn at 150×50 and scaled by a whole number to exactly 1500×500 (3:1), so every pixel stays a crisp square.

<p align="center"><img src="https://raw.githubusercontent.com/BotHarness/BotPixel/main/assets/banner-scenes-light.png" alt="All ten banner scenes on a light page" width="100%"></p>

```ts
import { pixelBannerImage, seededBannerRecipe } from '@botharness/pixel-banner';

const recipe = seededBannerRecipe('DeepSeekBot'); // { scene: 'sea', seed: 2786543041 }, same name, same banner
const { width, height, data } = pixelBannerImage(recipe); // 1500×500 RGBA

const canvas = document.createElement('canvas');
canvas.width = width;
canvas.height = height;
canvas.getContext('2d')!.putImageData(new ImageData(data, width, height), 0, 0);
canvas.toBlob((png) => upload(png!), 'image/png');
```

- `BANNER_SCENES`: `spring`, `summer`, `autumn`, `winter`, `sea`, `mountain`, `desert`, `forest`, `night-sky`, `space`.
- A recipe is plain JSON: `{ scene, seed }`, where `seed` is a 32-bit unsigned integer. `isPixelBannerRecipe` validates a saved one.
- `seededBannerRecipe(name)`: the same name always gives the same recipe.
- `pixelBannerPixels(recipe)`: the 150×50 source pixels. Draw it on a 150×50 canvas and scale it with CSS `image-rendering: pixelated` if you do not need the full-size file.
- `pixelBannerImage(recipe, { scale })`: the pixels repeated `scale` times (default `BANNER_SCALE`, 10), with no smoothing. `scalePixels(image, scale)` does the same for any image.

Output is RGBA, row-major, 4 bytes per pixel, fully opaque. It uses only integer and basic float arithmetic, so the same recipe gives the same bytes in every JavaScript engine. `test/fixtures/banner-golden.json` locks the output of every scene; a change that alters existing banners needs a new scene name, not a new fixture.
46 changes: 46 additions & 0 deletions packages/banner/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"name": "@botharness/pixel-banner",
"version": "0.1.0",
"description": "Seeded pixel-art nature banners (3:1, 1500×500) in ten scenes, as crisp RGBA pixels",
"keywords": [
"banner",
"generator",
"header",
"pixel-art",
"procedural",
"profile"
],
"homepage": "https://github.com/BotHarness/BotPixel",
"bugs": {
"url": "https://github.com/BotHarness/BotPixel/issues"
},
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/BotHarness/BotPixel.git",
"directory": "packages/banner"
},
"files": [
"dist"
],
"type": "module",
"sideEffects": false,
"main": "./dist/index.js",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"./package.json": "./package.json"
},
"scripts": {
"build": "tsdown",
"typecheck": "tsc --noEmit"
},
"devDependencies": {
"tsdown": "^0.20.0",
"typescript": "^5.9.3"
}
}
139 changes: 139 additions & 0 deletions packages/banner/src/grid.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
import type { Random } from './random.js';

export type Rgb = number;

export const hex = (value: string): Rgb => Number.parseInt(value.slice(1), 16);

const BAYER = [0, 8, 2, 10, 12, 4, 14, 6, 3, 11, 1, 9, 15, 7, 13, 5];

// ordered-dither threshold in (0, 1) for a pixel, the classic 4×4 Bayer matrix
export const bayer = (x: number, y: number): number => (BAYER[(y & 3) * 4 + (x & 3)]! + 0.5) / 16;

const smooth = (t: number): number => t * t * (3 - 2 * t);

export class Grid {
readonly data: Uint8ClampedArray;

constructor(
readonly width: number,
readonly height: number,
) {
this.data = new Uint8ClampedArray(width * height * 4);
}

set(x: number, y: number, color: Rgb): void {
x = Math.round(x);
y = Math.round(y);
if (x < 0 || y < 0 || x >= this.width || y >= this.height) return;
const o = (y * this.width + x) * 4;
this.data[o] = (color >> 16) & 255;
this.data[o + 1] = (color >> 8) & 255;
this.data[o + 2] = color & 255;
this.data[o + 3] = 255;
}

get(x: number, y: number): Rgb {
const o = (y * this.width + x) * 4;
return (this.data[o]! << 16) | (this.data[o + 1]! << 8) | this.data[o + 2]!;
}

rect(x: number, y: number, w: number, h: number, color: Rgb): void {
for (let j = y; j < y + h; j++) for (let i = x; i < x + w; i++) this.set(i, j, color);
}

disc(cx: number, cy: number, r: number, color: Rgb): void {
for (let y = Math.floor(cy - r); y <= cy + r; y++)
for (let x = Math.floor(cx - r); x <= cx + r; x++)
if ((x - cx) ** 2 + (y - cy) ** 2 <= r * r + r * 0.8) this.set(x, y, color);
}

// vertical bands between colour stops, ordered-dithered where two stops meet
gradient(stops: readonly Rgb[], top = 0, bottom = this.height): void {
const span = Math.max(1, bottom - top - 1);
for (let y = top; y < bottom; y++) {
const t = ((y - top) / span) * (stops.length - 1);
const i = Math.min(stops.length - 2, Math.floor(t));
const f = t - i;
for (let x = 0; x < this.width; x++)
this.set(x, y, f > bayer(x, y) ? stops[i + 1]! : stops[i]!);
}
}

fillBelow(tops: readonly number[], color: Rgb, bottom = this.height): void {
tops.forEach((top, x) => {
for (let y = Math.round(top); y < bottom; y++) this.set(x, y, color);
});
}

edge(tops: readonly number[], color: Rgb): void {
tops.forEach((top, x) => this.set(x, Math.round(top), color));
}
}

// a smooth 1-D skyline: value noise in a few octaves around `base`
export function ridge(
rnd: Random,
width: number,
base: number,
amplitude: number,
step: number,
octaves = 2,
): number[] {
const tops = Array.from({ length: width }, () => base);
let amp = amplitude;
let span = step;
for (let o = 0; o < octaves; o++) {
const points = Array.from({ length: Math.ceil(width / span) + 2 }, () => rnd() * 2 - 1);
for (let x = 0; x < width; x++) {
const i = Math.floor(x / span);
const t = smooth((x % span) / span);
tops[x]! += (points[i]! * (1 - t) + points[i + 1]! * t) * amp;
}
amp /= 2;
span = Math.max(2, Math.floor(span / 2));
}
return tops.map(Math.round);
}

// a mountain range: the highest of several jagged triangular peaks at each column
export function peaks(
rnd: Random,
width: number,
base: number,
count: number,
minHeight: number,
maxHeight: number,
): number[] {
const list = Array.from({ length: count }, (_, i) => ({
x: ((i + 0.2 + rnd() * 0.6) / count) * width,
h: minHeight + rnd() * (maxHeight - minHeight),
left: 0.45 + rnd() * 0.5,
right: 0.45 + rnd() * 0.5,
}));
const jitter = ridge(rnd, width, 0, 1.2, 3, 1);
return Array.from({ length: width }, (_, x) => {
let height = 0;
for (const p of list) {
const d = x - p.x;
height = Math.max(height, p.h - Math.abs(d) * (d < 0 ? p.left : p.right));
}
return Math.round(base - height + jitter[x]!);
});
}

// smooth 2-D value noise in [0, 1], for clouds of gas and mist
export function field(rnd: Random, width: number, height: number, cell: number) {
const cols = Math.ceil(width / cell) + 2;
const rows = Math.ceil(height / cell) + 2;
const values = Array.from({ length: cols * rows }, () => rnd());
return (x: number, y: number): number => {
const i = Math.floor(x / cell);
const j = Math.floor(y / cell);
const tx = smooth((x % cell) / cell);
const ty = smooth((y % cell) / cell);
const v = (a: number, b: number) => values[(j + b) * cols + i + a]!;
const top = v(0, 0) * (1 - tx) + v(1, 0) * tx;
const bottom = v(0, 1) * (1 - tx) + v(1, 1) * tx;
return top * (1 - ty) + bottom * ty;
};
}
Loading
Loading