Pixel Avatar

Description

An animated pixel-art cat that can perch on another component

PixelAvatar draws a sprite stored as a grid of palette indices, rendering every pixel as an absolutely positioned square. The avatar therefore scales crisply to any size (PixelSize) and can be recoloured by swapping its palette rather than by shipping another image.

The first constructor argument is a byte key. The same key always produces the same sprite, so an avatar derived from a user id, a node id or a hash stays stable across sessions. PixelAvatarDesign picks the colourway (Black, Orange, Siamese, Tuxedo, Sudo, and the rest), or SetPalette / SetShades / SetColor supply one of your own.

Play(PixelAvatarAnimation) runs a named animation (Idle, Move, Sit, Stretch, Startle, Sleep, JumpUp, …). AutoIdle is the behaviour rather than a pose: it holds one and every few seconds either stays put or drifts to another, wandering between standing, sitting and crouching, and falling asleep after SleepAfter. Wake brings it back, Pause / Resume / GoToFrame drive the animation directly, and Speed scales it. Facing, Turn and TurnAround change which way it looks.

AttachTo(component, anchor) perches the avatar on another component (a button, a card, an empty state) and returns a PixelAvatarAttachment whose Anchor moves it around the target.

Samples

A sitting avatar

Designs side by side, idling on their own

API reference

class

PixelAvatar

public sealed class PixelAvatar : ComponentBase<PixelAvatar, HTMLElement>

An animated pixel-art avatar. The artwork is stored as a grid of palette indices (see PixelAvatarSprites) and every pixel is rendered as an absolutely positioned square div, so the avatar scales crisply to any size and can be recolored by swapping its PixelAvatarPalette. Use AttachTo to perch the avatar on another component, for example on top of a button.

Namespace
Tesserae
Inheritance
ComponentBase<PixelAvatar, HTMLElement> → PixelAvatar

Constructors

NameDescription
PixelAvatarInitializes a new instance of this class.
Constructor
PixelAvatar
public PixelAvatar(byte key, PixelAvatarDesign design = PixelAvatarDesign.Black, PixelAvatarAnimation animation = PixelAvatarAnimation.Idle)

Initializes a new instance of this class.

Parameters

key
The key the sprite artwork is scrambled with. The library ships the sheet obfuscated and does not carry the key, so the application supplies it here; the first avatar constructed is what decodes the artwork for all of them.

Properties

NameDescription
DesignValueGets the design currently used by the component.
PaletteGets the palette currently used by the component.
CurrentAnimationGets the animation currently playing. While auto-idling this is whichever resting pose is showing, not AutoIdle.
IsAutoIdlingGets whether the avatar is drifting between resting poses on its own, which AutoIdle turns on and any other Play turns off.
IsAsleepGets whether the avatar is asleep, which for an auto-idling one happens on its own after SleepAfter of resting.
CurrentFrameGets the index of the frame currently shown.
RenderedWidthGets the rendered width of the avatar, in CSS pixels.
RenderedHeightGets the rendered height of the avatar, in CSS pixels.
PixelSizeValueGets or sets the size, in CSS pixels, of a single sprite pixel.
FacingValueGets or sets the direction the avatar faces.
IsPausedGets or sets whether playback is paused.
Property
PixelAvatar.DesignValue
public PixelAvatarDesign DesignValue

Gets the design currently used by the component.

Property
PixelAvatar.Palette
public PixelAvatarPalette Palette

Gets the palette currently used by the component.

Property
PixelAvatar.CurrentAnimation
public PixelAvatarAnimation CurrentAnimation

Gets the animation currently playing. While auto-idling this is whichever resting pose is showing, not AutoIdle.

Property
PixelAvatar.IsAutoIdling
public bool IsAutoIdling

Gets whether the avatar is drifting between resting poses on its own, which AutoIdle turns on and any other Play turns off.

Property
PixelAvatar.IsAsleep
public bool IsAsleep

Gets whether the avatar is asleep, which for an auto-idling one happens on its own after SleepAfter of resting.

Property
PixelAvatar.CurrentFrame
public int CurrentFrame

Gets the index of the frame currently shown.

Property
PixelAvatar.RenderedWidth
public int RenderedWidth

Gets the rendered width of the avatar, in CSS pixels.

Property
PixelAvatar.RenderedHeight
public int RenderedHeight

Gets the rendered height of the avatar, in CSS pixels.

Property
PixelAvatar.PixelSizeValue
public int PixelSizeValue { get ; set ; }

Gets or sets the size, in CSS pixels, of a single sprite pixel.

Property
PixelAvatar.FacingValue
public PixelAvatarFacing FacingValue { get ; set ; }

Gets or sets the direction the avatar faces.

Property
PixelAvatar.IsPaused
public bool IsPaused { get ; set ; }

Gets or sets whether playback is paused.

Methods

NameDescription
RestDelayOverrides how long the resting poses hold their first frame before playing their cycle, in milliseconds. The actual hold is picked uniformly from the range every time. Pass zero for both to go back to each animation's own timing.
SleepAfterSets how long an auto-idling avatar rests before falling asleep, in milliseconds. The value is jittered on use. Pass zero to keep it awake indefinitely. Only AutoIdle sleeps on its own; playing an animation directly never does.
WakeRestarts the countdown to SleepAfter and, if the avatar is currently asleep, wakes it with a stretch and a startle before handing it back to whatever it was doing - which for an auto-idling avatar means drifting between resting poses again.
SetDesignSets the design (and therefore the palette) of the component.
SetPaletteSets a custom palette, whose colors map to palette indices 1..N of the sprite data.
SetShadesSets a custom palette built from the artwork's three shading levels, the way the single-hue built-in designs are built.
SetColorRecolors a single palette index. This only rewrites that index's CSS variable, so it is cheap enough to drive from a color picker's input event.
PixelSizeSets the size, in CSS pixels, of a single sprite pixel. The rendered avatar ends up PixelAvatarSprites.FrameWidth * pixelSize wide.
FacingSets the direction the avatar faces, mirroring the artwork when facing left. The change is instant; use Turn to animate it.
TurnChanges the direction the avatar faces by pivoting it about its vertical axis, so it reads as the sprite turning around rather than its pixels swapping sides. Facing the direction it already faces does nothing.
TurnAroundPivots the avatar to face the other way. See Turn.
OutlineSets whether the sprite is drawn with a hairline halo in the theme's contrasting color. It is on by default because several palettes are pure white and several are near-black, so without it those designs disappear against one theme or the other. Turn it off when the avatar sits on a background you control and you want the artwork's colors untouched.
OutlineColorOverrides the color of the halo drawn by Outline, which defaults to a translucent black in light mode and a translucent white in dark mode.
SpeedMultiplies the playback speed of every animation. Values above 1 play faster.
PlayPlays an animation from its first frame. Animations that do not loop hand over to a follow-up animation when they finish (see Next).
PausePauses playback on the current frame.
ResumeResumes playback from the current frame.
GoToFrameShows a specific frame of the current animation without changing playback state.
OnAnimationFinishedRegisters a callback invoked when a non-looping animation reaches its last frame, just before its follow-up animation takes over. Calling Play from the callback suppresses that hand-over.
OnAnimationStartedRegisters a callback invoked whenever a new animation starts playing.
AttachToWraps target so that this avatar is anchored to one of its edges. The returned component renders the target as usual, with the avatar perched next to it. A Modal target is not wrapped - see IsAdopted.
AsButtonWraps the avatar in a Button that has no background, border, padding or minimum size, so it hugs the avatar exactly instead of the button's usual chrome. The avatar becomes the button's content via ReplaceContent - the cat itself is the clickable surface - and the button's size tracks RenderedWidth / RenderedHeight, so it stays a perfect fit if PixelSize later changes. This claims the same pixel-size tracking slot AttachTo uses, so an avatar already attached to another component should not also be turned into a button.
RenderRenders the component's root HTML element.
Method
PixelAvatar.RestDelay
public PixelAvatar RestDelay(int minMs, int maxMs)

Overrides how long the resting poses hold their first frame before playing their cycle, in milliseconds. The actual hold is picked uniformly from the range every time. Pass zero for both to go back to each animation's own timing.

Method
PixelAvatar.SleepAfter
public PixelAvatar SleepAfter(int milliseconds)

Sets how long an auto-idling avatar rests before falling asleep, in milliseconds. The value is jittered on use. Pass zero to keep it awake indefinitely. Only AutoIdle sleeps on its own; playing an animation directly never does.

Method
PixelAvatar.Wake
public PixelAvatar Wake()

Restarts the countdown to SleepAfter and, if the avatar is currently asleep, wakes it with a stretch and a startle before handing it back to whatever it was doing - which for an auto-idling avatar means drifting between resting poses again.

Method
PixelAvatar.SetDesign
public PixelAvatar SetDesign(PixelAvatarDesign design)

Sets the design (and therefore the palette) of the component.

Method
PixelAvatar.SetPalette
public PixelAvatar SetPalette(PixelAvatarPalette palette)

Sets a custom palette, whose colors map to palette indices 1..N of the sprite data.

Method
PixelAvatar.SetShades
public PixelAvatar SetShades(Color highlight, Color baseColor, Color shadow, Color background = null, string name = "Custom")

Sets a custom palette built from the artwork's three shading levels, the way the single-hue built-in designs are built.

Method
PixelAvatar.SetColor
public PixelAvatar SetColor(byte index, Color color)

Recolors a single palette index. This only rewrites that index's CSS variable, so it is cheap enough to drive from a color picker's input event.

Method
PixelAvatar.PixelSize
public PixelAvatar PixelSize(int pixelSize)

Sets the size, in CSS pixels, of a single sprite pixel. The rendered avatar ends up PixelAvatarSprites.FrameWidth * pixelSize wide.

Method
PixelAvatar.Facing
public PixelAvatar Facing(PixelAvatarFacing facing)

Sets the direction the avatar faces, mirroring the artwork when facing left. The change is instant; use Turn to animate it.

Method
PixelAvatar.Turn
public PixelAvatar Turn(PixelAvatarFacing facing, int durationMs = DefaultTurnDurationMs)

Changes the direction the avatar faces by pivoting it about its vertical axis, so it reads as the sprite turning around rather than its pixels swapping sides. Facing the direction it already faces does nothing.

Method
PixelAvatar.TurnAround
public PixelAvatar TurnAround(int durationMs = DefaultTurnDurationMs)

Pivots the avatar to face the other way. See Turn.

Method
PixelAvatar.Outline
public PixelAvatar Outline(bool value = true)

Sets whether the sprite is drawn with a hairline halo in the theme's contrasting color. It is on by default because several palettes are pure white and several are near-black, so without it those designs disappear against one theme or the other. Turn it off when the avatar sits on a background you control and you want the artwork's colors untouched.

Method
PixelAvatar.OutlineColor
public PixelAvatar OutlineColor(string color)

Overrides the color of the halo drawn by Outline, which defaults to a translucent black in light mode and a translucent white in dark mode.

Method
PixelAvatar.Speed
public PixelAvatar Speed(double speed)

Multiplies the playback speed of every animation. Values above 1 play faster.

Method
PixelAvatar.Play
public PixelAvatar Play(PixelAvatarAnimation animation)

Plays an animation from its first frame. Animations that do not loop hand over to a follow-up animation when they finish (see Next).

Method
PixelAvatar.Pause
public PixelAvatar Pause()

Pauses playback on the current frame.

Method
PixelAvatar.Resume
public PixelAvatar Resume()

Resumes playback from the current frame.

Method
PixelAvatar.GoToFrame
public PixelAvatar GoToFrame(int frame)

Shows a specific frame of the current animation without changing playback state.

Method
PixelAvatar.OnAnimationFinished
public PixelAvatar OnAnimationFinished(Action<PixelAvatar, PixelAvatarAnimation> onAnimationFinished, bool clearPrevious = true)

Registers a callback invoked when a non-looping animation reaches its last frame, just before its follow-up animation takes over. Calling Play from the callback suppresses that hand-over.

Method
PixelAvatar.OnAnimationStarted
public PixelAvatar OnAnimationStarted(Action<PixelAvatar, PixelAvatarAnimation> onAnimationStarted, bool clearPrevious = true)

Registers a callback invoked whenever a new animation starts playing.

Method
PixelAvatar.AttachTo
public PixelAvatarAttachment AttachTo(IComponent target, PixelAvatarAnchor anchor = PixelAvatarAnchor.TopLeft)

Wraps target so that this avatar is anchored to one of its edges. The returned component renders the target as usual, with the avatar perched next to it. A Modal target is not wrapped - see IsAdopted.

Method
PixelAvatar.AsButton
public Button AsButton()

Wraps the avatar in a Button that has no background, border, padding or minimum size, so it hugs the avatar exactly instead of the button's usual chrome. The avatar becomes the button's content via ReplaceContent - the cat itself is the clickable surface - and the button's size tracks RenderedWidth / RenderedHeight, so it stays a perfect fit if PixelSize later changes. This claims the same pixel-size tracking slot AttachTo uses, so an avatar already attached to another component should not also be turned into a button.

Method
PixelAvatar.Render
public override HTMLElement Render()

Renders the component's root HTML element.

Fields

NameDescription
DefaultPixelSizeThe default size, in CSS pixels, of a single sprite pixel.
DefaultTurnDurationMsThe default length, in milliseconds, of a Turn.
DefaultSleepAfterMsHow long an auto-idling avatar rests before falling asleep, in milliseconds. Jittered on use, so the cat does not nod off on a stopwatch.
Field
PixelAvatar.DefaultPixelSize
public const int DefaultPixelSize = 4

The default size, in CSS pixels, of a single sprite pixel.

Field
PixelAvatar.DefaultTurnDurationMs
public const int DefaultTurnDurationMs = 320

The default length, in milliseconds, of a Turn.

Field
PixelAvatar.DefaultSleepAfterMs
public const int DefaultSleepAfterMs = 16000

How long an auto-idling avatar rests before falling asleep, in milliseconds. Jittered on use, so the cat does not nod off on a stopwatch.

class

PixelAvatarAttachment

public sealed class PixelAvatarAttachment : IComponent, ISpecialCaseStyling

A component that renders another component with a PixelAvatar anchored to one of its edges. Created through AttachTo or WithPixelAvatar. By default the wrapper reserves room for the avatar on the anchored side, so the avatar stays inside the wrapper's box and cannot be clipped by a scrolling ancestor. Call Overlap to hang it outside the box instead, leaving the target's own footprint untouched. A Modal is the one target that is not wrapped: see IsAdopted.

Namespace
Tesserae
Implements
IComponent, ISpecialCaseStyling

Constructors

NameDescription
PixelAvatarAttachmentInitializes a new instance of this class.
Constructor
PixelAvatarAttachment
public PixelAvatarAttachment(IComponent target, PixelAvatar avatar, PixelAvatarAnchor anchor = PixelAvatarAnchor.TopLeft)

Initializes a new instance of this class.

Properties

NameDescription
AvatarGets the avatar anchored to the target.
TargetGets the component the avatar is anchored to.
IsAdoptedGets whether the target lends its own box to the avatar instead of being wrapped, which is what a Modal target does. An adopted target is still the component the application goes on using - Show and the rest all still apply - and this attachment's Render returns the target's own element. Adopted targets start in Overlap mode so the avatar sits outside the dialog.
CompanionGets the behaviour driving the avatar, or null when there is none. Set when the anchor is one of the Top* ones and the target is either an OmniBox or a Modal.
StylingContainerGets the element sizing helpers should style, which is the wrapper itself so the avatar stays anchored to the target's edges.
PropagateToStackItemParentGets whether styling should propagate to the stack item parent.
Property
PixelAvatarAttachment.Avatar
public PixelAvatar Avatar { get; }

Gets the avatar anchored to the target.

Property
PixelAvatarAttachment.Target
public IComponent Target { get; }

Gets the component the avatar is anchored to.

Property
PixelAvatarAttachment.IsAdopted
public bool IsAdopted { get; }

Gets whether the target lends its own box to the avatar instead of being wrapped, which is what a Modal target does. An adopted target is still the component the application goes on using - Show and the rest all still apply - and this attachment's Render returns the target's own element. Adopted targets start in Overlap mode so the avatar sits outside the dialog.

Property
PixelAvatarAttachment.Companion
public PixelAvatarCompanion Companion { get; }

Gets the behaviour driving the avatar, or null when there is none. Set when the anchor is one of the Top* ones and the target is either an OmniBox or a Modal.

Property
PixelAvatarAttachment.StylingContainer
public HTMLElement StylingContainer

Gets the element sizing helpers should style, which is the wrapper itself so the avatar stays anchored to the target's edges.

Property
PixelAvatarAttachment.PropagateToStackItemParent
public bool PropagateToStackItemParent

Gets whether styling should propagate to the stack item parent.

Methods

NameDescription
AnchorMoves the avatar to a different edge of the target.
OverlapLets the avatar hang outside the wrapper's box instead of reserving room for it, so the target keeps exactly the footprint it would have on its own. Beware that an avatar in overlap mode is clipped by any ancestor that scrolls or hides its overflow. An adopted Modal starts in overlap mode, so the cat perches on the outside of the dialog; Overlap(false) moves it into a reserved band inside instead.
OffsetNudges the avatar away from its anchor by a number of CSS pixels, with positive values moving it right and down.
RenderRenders the component's root HTML element.
Method
PixelAvatarAttachment.Anchor
public PixelAvatarAttachment Anchor(PixelAvatarAnchor anchor)

Moves the avatar to a different edge of the target.

Method
PixelAvatarAttachment.Overlap
public PixelAvatarAttachment Overlap(bool value = true)

Lets the avatar hang outside the wrapper's box instead of reserving room for it, so the target keeps exactly the footprint it would have on its own. Beware that an avatar in overlap mode is clipped by any ancestor that scrolls or hides its overflow. An adopted Modal starts in overlap mode, so the cat perches on the outside of the dialog; Overlap(false) moves it into a reserved band inside instead.

Method
PixelAvatarAttachment.Offset
public PixelAvatarAttachment Offset(int x, int y)

Nudges the avatar away from its anchor by a number of CSS pixels, with positive values moving it right and down.

Method
PixelAvatarAttachment.Render
public HTMLElement Render()

Renders the component's root HTML element.

class

PixelAvatarExtensions

public static class PixelAvatarExtensions

Fluent helpers for attaching a PixelAvatar to any component.

Namespace
Tesserae

Methods

NameDescription
WithPixelAvatarWraps the component so that avatar is perched on one of its edges.
Method
PixelAvatarExtensions.WithPixelAvatar
Overload
WithPixelAvatar(IComponent, PixelAvatar, PixelAvatarAnchor)Wraps the component so that avatar is perched on one of its edges.
WithPixelAvatar(IComponent, byte, PixelAvatarDesign, PixelAvatarAnchor)Wraps the component so that a new avatar with the given design is perched on one of its edges. The avatar is available through Avatar. See PixelAvatar for the key.
WithPixelAvatar(Modal, PixelAvatar, PixelAvatarAnchor)Perches an avatar on one of the modal's own edges. A modal lends its box to the avatar rather than being wrapped, so the modal itself is returned and the caller goes on using it as usual. Reach the attachment - and its companion - through AttachTo when you need to tune it.
WithPixelAvatar(Modal, byte, PixelAvatarDesign, PixelAvatarAnchor)Perches a new avatar with the given design on one of the modal's own edges. See PixelAvatar for the key.
WithPixelAvatar(IComponent, PixelAvatar, PixelAvatarAnchor)
public static PixelAvatarAttachment WithPixelAvatar(this IComponent component, PixelAvatar avatar, PixelAvatarAnchor anchor = PixelAvatarAnchor.TopLeft)

Wraps the component so that avatar is perched on one of its edges.

Parameters

component IComponent
avatar PixelAvatar
anchor PixelAvatarAnchor
WithPixelAvatar(IComponent, byte, PixelAvatarDesign, PixelAvatarAnchor)
public static PixelAvatarAttachment WithPixelAvatar(this IComponent component, byte key, PixelAvatarDesign design, PixelAvatarAnchor anchor = PixelAvatarAnchor.TopLeft)

Wraps the component so that a new avatar with the given design is perched on one of its edges. The avatar is available through Avatar. See PixelAvatar for the key.

Parameters

component IComponent
key byte
design PixelAvatarDesign
anchor PixelAvatarAnchor
WithPixelAvatar(Modal, PixelAvatar, PixelAvatarAnchor)
public static Modal WithPixelAvatar(this Modal modal, PixelAvatar avatar, PixelAvatarAnchor anchor = PixelAvatarAnchor.TopLeft)

Perches an avatar on one of the modal's own edges. A modal lends its box to the avatar rather than being wrapped, so the modal itself is returned and the caller goes on using it as usual. Reach the attachment - and its companion - through AttachTo when you need to tune it.

Parameters

modal Modal
avatar PixelAvatar
anchor PixelAvatarAnchor
WithPixelAvatar(Modal, byte, PixelAvatarDesign, PixelAvatarAnchor)
public static Modal WithPixelAvatar(this Modal modal, byte key, PixelAvatarDesign design, PixelAvatarAnchor anchor = PixelAvatarAnchor.TopLeft)

Perches a new avatar with the given design on one of the modal's own edges. See PixelAvatar for the key.

Parameters

modal Modal
key byte
design PixelAvatarDesign
anchor PixelAvatarAnchor
enum

PixelAvatarAnimation

public enum PixelAvatarAnimation

The animations a PixelAvatar can play. The four *Idle animations loop forever; the others play once and then hand over to a follow-up animation (for example Sit settles into SitIdle). AutoIdle is the odd one out: it has no artwork of its own and is a resting behaviour rather than a single animation.

Namespace
Tesserae

Values

NameDescription
AutoIdleRest naturally: hold a pose, and every few seconds either stay put or drift to another one, wandering between standing, sitting and crouching. Starts from Idle; CurrentAnimation reports whichever pose is actually showing, and IsAutoIdling reports the behaviour.
Value
PixelAvatarAnimation.AutoIdle
AutoIdle

Rest naturally: hold a pose, and every few seconds either stay put or drift to another one, wandering between standing, sitting and crouching. Starts from Idle; CurrentAnimation reports whichever pose is actually showing, and IsAutoIdling reports the behaviour.

enum

PixelAvatarFacing

public enum PixelAvatarFacing

The direction a PixelAvatar faces. The artwork is drawn facing Right; Left mirrors it horizontally.

Namespace
Tesserae
enum

PixelAvatarAnchor

public enum PixelAvatarAnchor

Where a PixelAvatar is placed relative to the component it is attached to. The Top* and Bottom* anchors perch the avatar just outside the target's edge, so a cat attached with TopLeft appears to be sitting on top of it.

Namespace
Tesserae
enum

PixelAvatarShade

public enum PixelAvatarShade

The three shading levels the artwork is drawn with. Every palette index belongs to exactly one of them, which is why a whole coat can be described by just three colors — see ShadeOf and FromShades.

Namespace
Tesserae
class

PixelSprite

public sealed class PixelSprite

A single animation frame: a grid of palette indices, where 0 means transparent and any other value indexes into a PixelAvatarPalette.

Namespace
Tesserae

Constructors

NameDescription
PixelSpriteInitializes a new instance of this class from a row-major grid of palette indices.
Constructor
PixelSprite
public PixelSprite(int width, int height, byte[] pixels)

Initializes a new instance of this class from a row-major grid of palette indices.

Properties

NameDescription
WidthGets the width of the frame, in sprite pixels.
HeightGets the height of the frame, in sprite pixels.
PixelsGets the palette index of every pixel, row by row (so the pixel at (x, y) lives at y * Width + x). A value of 0 means the pixel is transparent.
HasEarsGets whether this frame has a locatable pair of ear tips.
EarYGets the row both ear tips sit on. Only meaningful when HasEars.
EarLeftXGets the column of the left ear tip. Only meaningful when HasEars.
EarRightXGets the column of the right ear tip. Only meaningful when HasEars.
InkLeftGets the left edge of the frame's non-transparent pixels.
InkTopGets the top edge of the frame's non-transparent pixels.
InkWidthGets the width of the frame's non-transparent pixels, or 0 if there are none.
InkHeightGets the height of the frame's non-transparent pixels, or 0 if there are none.
Property
PixelSprite.Width
public int Width { get; }

Gets the width of the frame, in sprite pixels.

Property
PixelSprite.Height
public int Height { get; }

Gets the height of the frame, in sprite pixels.

Property
PixelSprite.Pixels
public byte[] Pixels { get; }

Gets the palette index of every pixel, row by row (so the pixel at (x, y) lives at y * Width + x). A value of 0 means the pixel is transparent.

Property
PixelSprite.HasEars
public bool HasEars { get ; }

Gets whether this frame has a locatable pair of ear tips.

Property
PixelSprite.EarY
public int EarY { get ; }

Gets the row both ear tips sit on. Only meaningful when HasEars.

Property
PixelSprite.EarLeftX
public int EarLeftX { get ; }

Gets the column of the left ear tip. Only meaningful when HasEars.

Property
PixelSprite.EarRightX
public int EarRightX { get ; }

Gets the column of the right ear tip. Only meaningful when HasEars.

Property
PixelSprite.InkLeft
public int InkLeft { get ; }

Gets the left edge of the frame's non-transparent pixels.

Property
PixelSprite.InkTop
public int InkTop { get ; }

Gets the top edge of the frame's non-transparent pixels.

Property
PixelSprite.InkWidth
public int InkWidth { get ; }

Gets the width of the frame's non-transparent pixels, or 0 if there are none.

Property
PixelSprite.InkHeight
public int InkHeight { get ; }

Gets the height of the frame's non-transparent pixels, or 0 if there are none.

Methods

NameDescription
AtReturns the palette index at the given coordinates, or 0 when out of bounds.
Method
PixelSprite.At
public byte At(int x, int y)

Returns the palette index at the given coordinates, or 0 when out of bounds.

class

PixelSpriteAnimation

public sealed class PixelSpriteAnimation

A sequence of PixelSprite frames plus the timing and chaining rules used to play them.

Namespace
Tesserae

Constructors

NameDescription
PixelSpriteAnimationInitializes a new instance of this class.
Constructor
PixelSpriteAnimation
public PixelSpriteAnimation(PixelAvatarAnimation animation, PixelSprite[] frames, int frameDurationMs, bool loops, PixelAvatarAnimation next, int restMinMs = 0, int restMaxMs = 0)

Initializes a new instance of this class.

Properties

NameDescription
AnimationGets the animation these frames belong to.
FramesGets the frames, in playback order.
FrameDurationMsGets how long each frame is shown, in milliseconds.
LoopsGets whether playback restarts from the first frame after the last one.
NextGets the animation that takes over once this one finishes. Only meaningful when Loops is false.
RestMinMsGets the shortest time this animation holds its first frame before playing on, in milliseconds. Zero means it cycles continuously.
RestMaxMsGets the longest such hold, in milliseconds.
RestsGets whether this animation rests on its first frame rather than cycling continuously. The resting poses do: a cat looping three frames forever reads as fidgeting, while one that holds still and twitches every few seconds reads as resting.
DurationMsGets how long a full cycle of this animation takes, in milliseconds, not counting any Rests hold.
Property
PixelSpriteAnimation.Animation
public PixelAvatarAnimation Animation { get; }

Gets the animation these frames belong to.

Property
PixelSpriteAnimation.Frames
public PixelSprite[] Frames { get; }

Gets the frames, in playback order.

Property
PixelSpriteAnimation.FrameDurationMs
public int FrameDurationMs { get; }

Gets how long each frame is shown, in milliseconds.

Property
PixelSpriteAnimation.Loops
public bool Loops { get; }

Gets whether playback restarts from the first frame after the last one.

Property
PixelSpriteAnimation.Next
public PixelAvatarAnimation Next { get; }

Gets the animation that takes over once this one finishes. Only meaningful when Loops is false.

Property
PixelSpriteAnimation.RestMinMs
public int RestMinMs { get; }

Gets the shortest time this animation holds its first frame before playing on, in milliseconds. Zero means it cycles continuously.

Property
PixelSpriteAnimation.RestMaxMs
public int RestMaxMs { get; }

Gets the longest such hold, in milliseconds.

Property
PixelSpriteAnimation.Rests
public bool Rests

Gets whether this animation rests on its first frame rather than cycling continuously. The resting poses do: a cat looping three frames forever reads as fidgeting, while one that holds still and twitches every few seconds reads as resting.

Property
PixelSpriteAnimation.DurationMs
public int DurationMs

Gets how long a full cycle of this animation takes, in milliseconds, not counting any Rests hold.

class

PixelAvatarRandom

internal static class PixelAvatarRandom

Random numbers for the avatar's own timing. Exists because Random.Next(minValue, maxValue) is broken under Transpose - it always returns minValue - so everything goes through the single-argument overload, which works.

Namespace
Tesserae

Methods

NameDescription
JitteredSpreads a delay by a fraction of itself, so a timing that is configured as one number still does not tick like a metronome. A cat that does everything on the beat reads as a machine.
Method
PixelAvatarRandom.Jittered
internal static int Jittered(int milliseconds, double fraction = DefaultJitter)

Spreads a delay by a fraction of itself, so a timing that is configured as one number still does not tick like a metronome. A cat that does everything on the beat reads as a machine.

Fields

NameDescription
DefaultJitterHow far a single-valued delay is spread either side of itself, by default.
Field
PixelAvatarRandom.DefaultJitter
internal const double DefaultJitter = 0.2

How far a single-valued delay is spread either side of itself, by default.

class

PixelAvatarPalette

public sealed class PixelAvatarPalette

The colors a PixelAvatar paints its sprite with, plus the background an avatar-shaped host such as PixelAvatarBadge should sit it on. Palette index 0 is always transparent and is not stored, so Colors[0] is the color for index 1. Instances are immutable; the With* methods return modified copies.

Namespace
Tesserae

Constructors

NameDescription
PixelAvatarPaletteInitializes a new instance of this class from colors for palette indices 1..N.
Constructor
PixelAvatarPalette
public PixelAvatarPalette(string name, Color[] colors, Color background = null, Color accent = null)

Initializes a new instance of this class from colors for palette indices 1..N.

Parameters

name
The name of the palette.
colors
Exactly PaletteSize colors.
background
The avatar background color, or null to derive one from DominantColor.

Properties

NameDescription
NameGets the name of the palette.
ColorsGets the colors of palette indices 1..N, in order.
BackgroundGets the background color an avatar-shaped host paints behind the sprite. Only its hue is used by BackgroundGradient, which matches how Avatar colors itself.
AccentGets the highlight painted on the ear tips, or null when the design has none. It is not a palette index: it is drawn as an extra half-size pixel on top of each ear tip, so a design can carry a spot of color the shared artwork has no cell for.
Property
PixelAvatarPalette.Name
public string Name { get; }

Gets the name of the palette.

Property
PixelAvatarPalette.Colors
public Color[] Colors { get; }

Gets the colors of palette indices 1..N, in order.

Property
PixelAvatarPalette.Background
public Color Background { get; }

Gets the background color an avatar-shaped host paints behind the sprite. Only its hue is used by BackgroundGradient, which matches how Avatar colors itself.

Property
PixelAvatarPalette.Accent
public Color Accent { get; }

Gets the highlight painted on the ear tips, or null when the design has none. It is not a palette index: it is drawn as an extra half-size pixel on top of each ear tip, so a design can carry a spot of color the shared artwork has no cell for.

Methods

NameDescription
ColorAtReturns the color for a palette index, or null for the transparent index 0 and for indices this palette does not define.
CssAtReturns the CSS color for a palette index, or an empty string for the transparent index 0 and for indices this palette does not define.
BackgroundGradientReturns the CSS background for this palette, built from Background by the same GradientForHue the regular avatar uses, so a pixel-art badge and an initials avatar look like they came out of the same set.
DominantColorReturns the color that covers the most of the sprite, weighing each index by PixelCounts and adding up indices that share a color. Used to pick a background when one is not given.
WithColorReturns a copy of this palette with one index recolored.
WithBackgroundReturns a copy of this palette with a different avatar background color. This is how a custom palette picks the background its badge sits on; pass null to go back to one derived from the coat.
WithNameReturns a copy of this palette under a different name.
WithAccentReturns a copy of this palette with a different ear-tip Accent. Pass null to drop it.
ToStringReturns the palette as a comma-separated list of CSS colors.
ToCodeReturns C# source that reconstructs this palette, for pasting into an application.
FromColorsBuilds a palette from every color of the sprite.
FromShadesBuilds a full palette from just the artwork's three shading levels, the way the single-hue built-in designs are built. Every palette index is filled in according to ShadeOf.
Method
PixelAvatarPalette.ColorAt
public Color ColorAt(byte index)

Returns the color for a palette index, or null for the transparent index 0 and for indices this palette does not define.

Method
PixelAvatarPalette.CssAt
public string CssAt(byte index)

Returns the CSS color for a palette index, or an empty string for the transparent index 0 and for indices this palette does not define.

Method
PixelAvatarPalette.BackgroundGradient
public string BackgroundGradient()

Returns the CSS background for this palette, built from Background by the same GradientForHue the regular avatar uses, so a pixel-art badge and an initials avatar look like they came out of the same set.

Method
PixelAvatarPalette.DominantColor
public Color DominantColor()

Returns the color that covers the most of the sprite, weighing each index by PixelCounts and adding up indices that share a color. Used to pick a background when one is not given.

Method
PixelAvatarPalette.WithColor
public PixelAvatarPalette WithColor(byte index, Color color)

Returns a copy of this palette with one index recolored.

Method
PixelAvatarPalette.WithBackground
public PixelAvatarPalette WithBackground(Color background)

Returns a copy of this palette with a different avatar background color. This is how a custom palette picks the background its badge sits on; pass null to go back to one derived from the coat.

Method
PixelAvatarPalette.WithName
public PixelAvatarPalette WithName(string name)

Returns a copy of this palette under a different name.

Method
PixelAvatarPalette.WithAccent
public PixelAvatarPalette WithAccent(Color accent)

Returns a copy of this palette with a different ear-tip Accent. Pass null to drop it.

Method
PixelAvatarPalette.ToString
public override string ToString()

Returns the palette as a comma-separated list of CSS colors.

Method
PixelAvatarPalette.ToCode
public string ToCode()

Returns C# source that reconstructs this palette, for pasting into an application.

Method
PixelAvatarPalette.FromColors
public static PixelAvatarPalette FromColors(string name, Color background, params Color[] colors)

Builds a palette from every color of the sprite.

Parameters

name
The name of the palette.
background
The avatar background color, or null to derive one from the coat.
colors
Exactly PaletteSize colors, for palette indices 1..N.

Exceptions

ArgumentException
Thrown when the wrong number of colors is given.
Method
PixelAvatarPalette.FromShades
public static PixelAvatarPalette FromShades(string name, Color background, Color highlight, Color baseColor, Color shadow, Color accent = null)

Builds a full palette from just the artwork's three shading levels, the way the single-hue built-in designs are built. Every palette index is filled in according to ShadeOf.

Parameters

name
The name of the palette.
background
The avatar background color, or null to derive one from the coat.
class

PixelAvatarBadge

public sealed class PixelAvatarBadge : ComponentBase<PixelAvatarBadge, HTMLElement>

A PixelAvatar dressed as a round profile picture, sized with the same AvatarSize presets as Avatar so the two can sit side by side in a ChatMessage or a list. The cat sits still — SitIdle, held on its first frame — because a badge is an identity, not an animation, and a transcript full of moving cats is unreadable. The background is the palette's own Background, run through the same gradient formula a regular Avatar uses.

Namespace
Tesserae
Inheritance
ComponentBase<PixelAvatarBadge, HTMLElement> → PixelAvatarBadge

Constructors

NameDescription
PixelAvatarBadgeInitializes a new instance of this class for one of the built-in designs.
Constructor
PixelAvatarBadge
Overload
PixelAvatarBadge(byte, PixelAvatarDesign, AvatarSize)Initializes a new instance of this class for one of the built-in designs.
PixelAvatarBadge(PixelAvatar, AvatarSize)Initializes a new instance of this class wrapping an existing avatar. The avatar is put into SitIdle and paused.
PixelAvatarBadge(byte, PixelAvatarDesign, AvatarSize)
public PixelAvatarBadge(byte key, PixelAvatarDesign design = PixelAvatarDesign.Black, AvatarSize size = AvatarSize.Medium) : this(new PixelAvatar(key, design, PixelAvatarAnimation.SitIdle), size)

Initializes a new instance of this class for one of the built-in designs.

Parameters

key byte
design PixelAvatarDesign
size AvatarSize
PixelAvatarBadge(PixelAvatar, AvatarSize)
public PixelAvatarBadge(PixelAvatar avatar, AvatarSize size = AvatarSize.Medium)

Initializes a new instance of this class wrapping an existing avatar. The avatar is put into SitIdle and paused.

Parameters

avatar PixelAvatar
size AvatarSize

Properties

NameDescription
AvatarGets the avatar shown in the badge.
SizeValueGets or sets the size preset of the badge.
Property
PixelAvatarBadge.Avatar
public PixelAvatar Avatar

Gets the avatar shown in the badge.

Property
PixelAvatarBadge.SizeValue
public AvatarSize SizeValue { get ; set ; }

Gets or sets the size preset of the badge.

Methods

NameDescription
SizeSets the size of the badge, matching the Avatar presets.
SetDesignSets the design of the cat in the badge. The background follows the new palette unless Background has pinned one.
SetPaletteSets the palette of the cat in the badge. The background follows the new palette unless Background has pinned one.
BackgroundPins the CSS background of the badge instead of taking the palette's. Pass null to go back to the palette's.
RenderRenders the component's root HTML element.
Method
PixelAvatarBadge.Size
public PixelAvatarBadge Size(AvatarSize size)

Sets the size of the badge, matching the Avatar presets.

Method
PixelAvatarBadge.SetDesign
public PixelAvatarBadge SetDesign(PixelAvatarDesign design)

Sets the design of the cat in the badge. The background follows the new palette unless Background has pinned one.

Method
PixelAvatarBadge.SetPalette
public PixelAvatarBadge SetPalette(PixelAvatarPalette palette)

Sets the palette of the cat in the badge. The background follows the new palette unless Background has pinned one.

Method
PixelAvatarBadge.Background
public PixelAvatarBadge Background(string background)

Pins the CSS background of the badge instead of taking the palette's. Pass null to go back to the palette's.

Method
PixelAvatarBadge.Render
public override HTMLElement Render()

Renders the component's root HTML element.

class

PixelAvatarCompanion

public sealed class PixelAvatarCompanion

Gives a PixelAvatar perched on top of another component a life of its own: while you leave it alone the cat wanders along the top edge and plays the odd animation, and on an OmniBox it also settles back down when you type and, a little later, pads over to the text caret to watch you type. Resting - drifting between the idle, sitting and crouching poses, and eventually falling asleep - belongs to the avatar itself, through AutoIdle; the companion only supplies the activity in between and wakes the cat up when you come back to the box. Created automatically by AttachTo when the anchor is one of the Top* ones and the target is an OmniBox or a Modal, and reachable through Companion to tune the timings. Every delay below is jittered on use, so nothing the cat does lands on a stopwatch.

Namespace
Tesserae

Constructors

NameDescription
PixelAvatarCompanion
Constructor
PixelAvatarCompanion
internal PixelAvatarCompanion(OmniBox omniBox, PixelAvatar avatar, HTMLElement host, PixelAvatarAnchor anchor)

Parameters

omniBox
The box the cat reacts to, or null when there is none - a companion without one only roams, since there is nothing to be typed into and no caret to walk to.

Properties

NameDescription
AvatarGets the avatar this companion drives.
IsAsleepGets whether the cat is currently asleep.
Property
PixelAvatarCompanion.Avatar
public PixelAvatar Avatar

Gets the avatar this companion drives.

Property
PixelAvatarCompanion.IsAsleep
public bool IsAsleep

Gets whether the cat is currently asleep.

Methods

NameDescription
IdleDelaySets the range a spontaneous animation is scheduled within. Both bounds are clamped to at least DefaultMinIdleMs so the cat never becomes a distraction. The actual delay is drawn uniformly from the range every time.
RestDelaySets how long the resting poses hold before the cat shifts to another one. See RestDelay; passing zero for both restores the built-in timing.
CursorDelaySets how long the cat waits after your last keystroke before padding over to the text caret. Pass zero to leave the caret alone entirely. Ignored by a companion with no box to watch.
SleepAfterSets how long the box has to stay untouched before the cat falls asleep. Pass zero to keep it awake indefinitely.
WalkSpeedSets how fast the cat walks, in CSS pixels per second.
WakeUpWakes the cat if it is asleep and restarts the sleep countdown.
FidgetPlays a spontaneous animation right now, as if the timer had fired.
FollowCursorWalks the cat over to the text caret right now, as if the countdown had elapsed.
Method
PixelAvatarCompanion.IdleDelay
public PixelAvatarCompanion IdleDelay(int minMs, int maxMs)

Sets the range a spontaneous animation is scheduled within. Both bounds are clamped to at least DefaultMinIdleMs so the cat never becomes a distraction. The actual delay is drawn uniformly from the range every time.

Method
PixelAvatarCompanion.RestDelay
public PixelAvatarCompanion RestDelay(int minMs, int maxMs)

Sets how long the resting poses hold before the cat shifts to another one. See RestDelay; passing zero for both restores the built-in timing.

Method
PixelAvatarCompanion.CursorDelay
public PixelAvatarCompanion CursorDelay(int milliseconds)

Sets how long the cat waits after your last keystroke before padding over to the text caret. Pass zero to leave the caret alone entirely. Ignored by a companion with no box to watch.

Method
PixelAvatarCompanion.SleepAfter
public PixelAvatarCompanion SleepAfter(int milliseconds)

Sets how long the box has to stay untouched before the cat falls asleep. Pass zero to keep it awake indefinitely.

Method
PixelAvatarCompanion.WalkSpeed
public PixelAvatarCompanion WalkSpeed(int pixelsPerSecond)

Sets how fast the cat walks, in CSS pixels per second.

Method
PixelAvatarCompanion.WakeUp
public PixelAvatarCompanion WakeUp()

Wakes the cat if it is asleep and restarts the sleep countdown.

Method
PixelAvatarCompanion.Fidget
public PixelAvatarCompanion Fidget()

Plays a spontaneous animation right now, as if the timer had fired.

Method
PixelAvatarCompanion.FollowCursor
public PixelAvatarCompanion FollowCursor()

Walks the cat over to the text caret right now, as if the countdown had elapsed.

Fields

NameDescription
DefaultMinIdleMsShortest gap between spontaneous animations, in milliseconds.
DefaultMaxIdleMsLongest gap between spontaneous animations, in milliseconds.
DefaultCursorDelayMsHow long the cat waits after you stop typing before walking to the caret, in milliseconds.
DefaultWalkSpeedPxPerSecondWalking speed, in CSS pixels per second.
DefaultSleepAfterMsHow long the box has to stay untouched before the cat sleeps, in milliseconds. Sleeping is the avatar's own doing, so this is just DefaultSleepAfterMs.
Field
PixelAvatarCompanion.DefaultMinIdleMs
public const int DefaultMinIdleMs = 5000

Shortest gap between spontaneous animations, in milliseconds.

Field
PixelAvatarCompanion.DefaultMaxIdleMs
public const int DefaultMaxIdleMs = 14000

Longest gap between spontaneous animations, in milliseconds.

Field
PixelAvatarCompanion.DefaultCursorDelayMs
public const int DefaultCursorDelayMs = 10000

How long the cat waits after you stop typing before walking to the caret, in milliseconds.

Field
PixelAvatarCompanion.DefaultWalkSpeedPxPerSecond
public const int DefaultWalkSpeedPxPerSecond = 55

Walking speed, in CSS pixels per second.

Field
PixelAvatarCompanion.DefaultSleepAfterMs
public const int DefaultSleepAfterMs = PixelAvatar.DefaultSleepAfterMs

How long the box has to stay untouched before the cat sleeps, in milliseconds. Sleeping is the avatar's own doing, so this is just DefaultSleepAfterMs.

See also

© 2026 Curiosity. All rights reserved.