New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@tomtev/touchgrass-avatar

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tomtev/touchgrass-avatar

Pixel art avatar system. 32M+ unique characters from a 7-char hex DNA string.

latest
Source
npmnpm
Version
0.1.0
Version published
Maintainers
1
Created
Source

@touchgrass/avatar

Pixel-art avatar system for touchgrass.sh. Each avatar is encoded as a 7-character hex DNA string (~32M combinations) that deterministically renders a unique character with hat, eyes, mouth, body, legs, and two independent color hues.

Install

npm install @touchgrass/avatar
# or
bun add @touchgrass/avatar

Usage

Core (framework-agnostic)

import {
  generateRandomDNA,
  decodeDNA,
  encodeDNA,
  generateGrid,
  traitsFromName,
  renderSVG,
  renderTerminal,
  renderTerminalSmall,
  hslToRgb,
  SLOTS,
  EYES, MOUTHS, HATS, BODIES, LEGS,
} from '@touchgrass/avatar';

Generate a random avatar

const dna = generateRandomDNA(); // e.g. "0a3f201"

Decode / encode DNA

const traits = decodeDNA('0a3f201');
// { eyes: 0, mouth: 2, hat: 5, body: 1, legs: 3, faceHue: 8, hatHue: 2 }

const dna = encodeDNA(traits); // "0a3f201"

Derive avatar from a name (no DNA needed)

const traits = traitsFromName('my-agent');
// Deterministic — same name always produces same traits

Render to SVG string

const svg = renderSVG('0a3f201');           // default 10px per pixel
const svg = renderSVG('0a3f201', 20);       // 20px per pixel
const svg = renderSVG('0a3f201', 10, 1);    // walking frame 1

Returns a complete <svg> string with transparent background. Use it as innerHTML, write to a .svg file, or embed in an <img> via data URI.

Render to terminal (ANSI)

const ansi = renderTerminal('0a3f201');      // full size (██ per pixel)
const ansi = renderTerminalSmall('0a3f201'); // compact (half-block ▀▄)

console.log(ansi);

Generate the pixel grid directly

const grid = generateGrid(traits, walkFrame, talkFrame, waveFrame);
// Pixel[][] — 9 columns wide, variable rows tall

Svelte

<script>
  import { Avatar } from '@touchgrass/avatar/svelte';
</script>

<!-- From DNA string -->
<Avatar dna="0a3f201" />

<!-- From name (deterministic hash) -->
<Avatar name="my-agent" />

<!-- Sizes: sm (3px), lg (8px, default), xl (14px) -->
<Avatar dna="0a3f201" size="xl" />

<!-- Animations -->
<Avatar dna="0a3f201" walking />
<Avatar dna="0a3f201" talking />
<Avatar dna="0a3f201" waving />

Props:

PropTypeDefaultDescription
dnastring7-char hex DNA string
namestringFallback: derive traits from name hash
size'sm' | 'lg' | 'xl''lg'Pixel size (3/8/14px per cell)
walkingbooleanfalseAnimate legs
talkingbooleanfalseAnimate mouth
wavingbooleanfalseAnimate arms

Either dna or name should be provided. If both are set, dna takes priority.

DNA Encoding

7 traits packed into a single integer using mixed-radix encoding with fixed slot sizes for forward compatibility:

TraitVariantsSlot sizeDescription
eyes1112normal, wide, close, big, squint, narrow, etc.
mouths712smile, smirk, narrow, wide variants
hats2424none, tophat, beanie, crown, cap, horns, mohawk, etc.
bodies68normal, narrow, tapered (each with/without arms)
legs68biped, quad, tentacles, thin, wide stance
faceHue12120-330 degrees in 30-degree steps
hatHue1212independent from face hue

Total slot space: 12 x 12 x 24 x 8 x 8 x 12 x 12 = 31,850,496 (~32M, 7 hex chars).

New variants can be added within slot limits without breaking existing DNA strings. Legacy 6-char DNAs decode identically (leading zero is implicit).

Pixel Grid

The avatar is a 9-column grid with variable height (depends on hat). Each cell is a Pixel type:

PixelMeaningRendering
fFace/bodySolid face color
eEyeSolid dark color
sSquint eyeFace bg + dark bottom half
nNarrow eyeFace bg + dark center strip
mMouthFace bg + dark top half
qSmile corner leftFace bg + dark bottom-right quarter
rSmile corner rightFace bg + dark bottom-left quarter
dDark accentSolid dark (hat bands, etc.)
hHatSolid hat color
lThin legHalf-width face color
kThin hat detailHalf-width hat color
aArmHalf-height face color
_TransparentEmpty

Colors

Each avatar has 3 colors derived from two hue indices (0-11, mapped to 0-330 degrees):

  • Face color: hsl(faceHue * 30, 50%, 50%)
  • Dark color: hsl(faceHue * 30, 50%, 28%) — eyes, mouth
  • Hat color: hsl(hatHue * 30, 50%, 50%)

Animations

The grid generator supports three animation types via frame parameters:

  • Walking (frame): Cycles through leg variant frames
  • Talking (talkFrame): 0 = normal mouth, 1+ = open mouth animation
  • Waving (waveFrame): 0 = normal body, 1+ = alternating arm positions

Exports

@touchgrass/avatar          — Core TypeScript (DNA, grid, SVG, terminal, colors)
@touchgrass/avatar/svelte   — Svelte 5 component (Avatar)

License

MIT

Keywords

avatar

FAQs

Package last updated on 24 Feb 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts