@benosjs/pixel 0.0.0-stage → 0.8.0
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/LICENSE +22 -0
- package/README.md +62 -2
- package/dist/js/index.development.js +2419 -0
- package/dist/js/index.development.js.map +1 -0
- package/dist/js/index.production.js +2119 -0
- package/dist/js/png.development.js +60 -0
- package/dist/js/png.development.js.map +1 -0
- package/dist/js/png.production.js +46 -0
- package/dist/types/ai.d.ts +37 -0
- package/dist/types/ai.d.ts.map +1 -0
- package/dist/types/character.d.ts +61 -0
- package/dist/types/character.d.ts.map +1 -0
- package/dist/types/color.d.ts +14 -0
- package/dist/types/color.d.ts.map +1 -0
- package/dist/types/draw.d.ts +27 -0
- package/dist/types/draw.d.ts.map +1 -0
- package/dist/types/font.d.ts +5 -0
- package/dist/types/font.d.ts.map +1 -0
- package/dist/types/format.d.ts +22 -0
- package/dist/types/format.d.ts.map +1 -0
- package/dist/types/index.d.ts +13 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/library/decor.d.ts +2 -0
- package/dist/types/library/decor.d.ts.map +1 -0
- package/dist/types/library/furniture.d.ts +2 -0
- package/dist/types/library/furniture.d.ts.map +1 -0
- package/dist/types/library/index.d.ts +9 -0
- package/dist/types/library/index.d.ts.map +1 -0
- package/dist/types/library/make.d.ts +6 -0
- package/dist/types/library/make.d.ts.map +1 -0
- package/dist/types/library/more.d.ts +2 -0
- package/dist/types/library/more.d.ts.map +1 -0
- package/dist/types/library/people.d.ts +2 -0
- package/dist/types/library/people.d.ts.map +1 -0
- package/dist/types/library/structure.d.ts +2 -0
- package/dist/types/library/structure.d.ts.map +1 -0
- package/dist/types/library/tech.d.ts +2 -0
- package/dist/types/library/tech.d.ts.map +1 -0
- package/dist/types/must.d.ts +6 -0
- package/dist/types/must.d.ts.map +1 -0
- package/dist/types/palette.d.ts +8 -0
- package/dist/types/palette.d.ts.map +1 -0
- package/dist/types/pixelate.d.ts +36 -0
- package/dist/types/pixelate.d.ts.map +1 -0
- package/dist/types/png.d.ts +4 -0
- package/dist/types/png.d.ts.map +1 -0
- package/dist/types/procedural.d.ts +91 -0
- package/dist/types/procedural.d.ts.map +1 -0
- package/dist/types/recolor.d.ts +14 -0
- package/dist/types/recolor.d.ts.map +1 -0
- package/dist/types/render.d.ts +13 -0
- package/dist/types/render.d.ts.map +1 -0
- package/dist/types/sheet.d.ts +19 -0
- package/dist/types/sheet.d.ts.map +1 -0
- package/package.json +39 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Benos contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
package/README.md
CHANGED
|
@@ -1,3 +1,63 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @benosjs/pixel
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
Pixel art for Benos. A sprite is a small text map plus a palette: one character
|
|
6
|
+
per pixel, a dot for transparent. Everything else in the package works on that
|
|
7
|
+
one format, so a sprite from the library, a generated creature and a converted
|
|
8
|
+
photo can all be recoloured, rendered and saved the same way.
|
|
9
|
+
|
|
10
|
+
```ts
|
|
11
|
+
import { findSprite, recolour, renderSprite } from '@benosjs/pixel'
|
|
12
|
+
|
|
13
|
+
const desk = findSprite('coding-desk')
|
|
14
|
+
if (desk) {
|
|
15
|
+
// Swap one palette entry, then draw it four times larger.
|
|
16
|
+
const pink = recolour(desk, { W: '#ff7ab6' })
|
|
17
|
+
const bitmap = renderSprite(pink, 4)
|
|
18
|
+
context.putImageData(
|
|
19
|
+
new ImageData(
|
|
20
|
+
new Uint8ClampedArray(bitmap.data),
|
|
21
|
+
bitmap.width,
|
|
22
|
+
bitmap.height,
|
|
23
|
+
),
|
|
24
|
+
0,
|
|
25
|
+
0,
|
|
26
|
+
)
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## What is in it
|
|
31
|
+
|
|
32
|
+
- **The format:** `Sprite`, `validateSprite`, and `Draw`, a small drawing board
|
|
33
|
+
for building a text map from rectangles, lines and circles.
|
|
34
|
+
- **Rendering:** `renderSprite` and `drawSprite` produce RGBA pixels that fit a
|
|
35
|
+
canvas `ImageData`. `packSheet` lays many sprites out on one sheet.
|
|
36
|
+
- **A sprite set:** `SPRITES` is a 62-piece tech office set in one shared
|
|
37
|
+
palette, and `SPRITE_ANIMATIONS` holds walk and idle frames for two
|
|
38
|
+
characters.
|
|
39
|
+
- **Recolouring:** `recolour`, `shiftHue`, `mapPalette` and a few presets.
|
|
40
|
+
- **A character builder:** `buildCharacter` stacks body, hair, clothes and an
|
|
41
|
+
accessory into a sprite; `animateCharacter` gives any of them a walk and an
|
|
42
|
+
idle.
|
|
43
|
+
- **Image to pixel art:** `pixelate` shrinks a bitmap, reduces it to a found or
|
|
44
|
+
fixed palette, and can dither.
|
|
45
|
+
- **Seeded generators:** `generateCreature`, `generateItem` and `generateTile`
|
|
46
|
+
return the same sprite for the same number.
|
|
47
|
+
|
|
48
|
+
The main entry uses no platform APIs and runs in a browser, on a server, or in
|
|
49
|
+
a worker. Writing PNG files needs Node and lives in its own entry:
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
import { writeFileSync } from 'node:fs'
|
|
53
|
+
import { findSprite, renderSprite } from '@benosjs/pixel'
|
|
54
|
+
import { encodePng } from '@benosjs/pixel/png'
|
|
55
|
+
|
|
56
|
+
const sprite = findSprite('rubber-duck')
|
|
57
|
+
if (sprite) writeFileSync('duck.png', encodePng(renderSprite(sprite, 8)))
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
In a browser, draw the bitmap to a canvas and let the browser encode it.
|
|
61
|
+
|
|
62
|
+
This package is not published yet. It is marked private until its first
|
|
63
|
+
release is decided.
|