Pixl is a browser pet with a clock, three counters and SVG sprites. Its rules decide when it sleeps, gets hungry or looks happy.


A pocket pet in the browser#

The visual reference is the pocket pet: a small creature with needs you can read on a tiny screen.

Pixl itself

Pixl uses deterministic rules to choose what the pet does. There is no server, no randomness, no hidden neural net. Only the browser’s Date object, three integers, and a handful of SVG sprites that look best on a pretend-CRT background.1

Pixl snoozing under a summer moon


Three changing values#

Stat Role Good direction
happiness emotional brightness higher
hunger distance from a full tummy lower
energy readiness to bounce on the screen higher

Every 30s the numbers drift:

happinesst+30=happinesst  −  2hungert+30=hungert  +  3energyt+30=energyt  −  1\begin{aligned} \text{happiness}_{t+30} &= \text{happiness}_{t}\;-\;2 \\ \text{hunger}_{t+30} &= \text{hunger}_{t} \;+ \;3 \\ \text{energy}_{t+30} &= \text{energy}_{t} \;- \;1 \end{aligned}

Left alone for half an hour Pixl grows hungry, drowsy, and a little gloomy.

Pixl stats


Following the local clock#

animation(h)  =  {sleeping  or  sleepy,h∈[22,24)∪[0,5)awake  and others,5≤h<22\text{animation}(h) \;=\; \begin{cases} \texttt{sleeping} \;\text{or}\; \texttt{sleepy}, & h \in [22,24) \cup [0,5) \\ \texttt{awake} \;\text{and others}, & 5 \le h < 22 \end{cases}

The clock is local to each visitor. A laptop in Tokyo and a phone in Tijuana can therefore show different scenes at the same instant. The pet stats are stored in each browser, too; there is no shared global creature.


Five rules#

  1. Circadian
    Pixl dozes whenever the local clock reads between 10 PM and 5 AM.

    h∈[22,24)∪[0,5)  ⟹  sleeping/sleepyh \in [22,24) \cup [0,5) \;\Longrightarrow\; \texttt{sleeping/sleepy}
  2. Dominant Need
    Physical necessities outrank mood: starving pixels grumble, exhausted ones sag.

    hunger>70  ⟹  idle_hungryenergy<20  ⟹  idle_tired\begin{aligned} \text{hunger} > 70 \;&\Longrightarrow\; \texttt{idle\_hungry}\\ \text{energy} < 20 \;&\Longrightarrow\; \texttt{idle\_tired} \end{aligned}
  3. Mood Gradient
    The emotional dial swings between 😊 , 😐 , and 😢 depending on morale.

    {happiness>70⇒idle_happyhappiness<30⇒idle_sadotherwise⇒idle_neutral\begin{cases} \text{happiness} > 70 &\Rightarrow \texttt{idle\_happy}\\[4pt] \text{happiness} < 30 &\Rightarrow \texttt{idle\_sad}\\[4pt] \text{otherwise} &\Rightarrow \texttt{idle\_neutral} \end{cases}
  4. Reinforcement
    More than five petting and playing interactions in 24 hours can trigger the ecstatic animation when Pixl is already happy.

    (pet+play)24h>5  ∧  animation=idle_happy  ⟹  idle_ecstatic(\text{pet}+\text{play})_{24h} > 5 \;\land\; \texttt{animation}=\texttt{idle\_happy} \;\Longrightarrow\; \texttt{idle\_ecstatic}
  5. Scarcity of Kindness
    Each action is limited to three uses per day.

    ∀ a∈{feed, pet, play},  countday(a)≤3\forall\,a \in \{\text{feed, pet, play}\},\; \text{count}_{\text{day}}(a) \le 3

Pixl stats text summary

The rules form a small hierarchy: hunger and fatigue take priority over mood.2


Drawing the sprites#

All art is plain SVG—8×88\times8 or 32×3232\times32 grids rendered with the property shapeRendering="crispEdges". The grids keep the shapes simple and the edges sharp.

Pixl idle sleeping

A sleeping Pixl, eyes closed.


A Walk Through the Source#

Conceived as a single event-loop, Pixl’s logic is a few hundred lines of lightweight JavaScript. The core function, tick, runs every 30 seconds, updating the creature’s state and rendering the scene.

function tick(now):  
  stats ← loadStats()   # from localStorage  
  stats ← decay(stats)  # metabolic drift  
  scenery ← chooseScenery(now)  
  animation ← chooseAnimation(stats, now)  
  render(scenery, animation, stats)

A few key functions drive the experience:

  • chooseScenery maps (month, hour) to spring morning, autumn night, or—on 25 December—christmas.
  • chooseAnimation applies the five axioms above.
  • Persistence is two keys in localStorage: one JSON object for stats, one ring-buffer for the last 100 interactions.

The sprites and state transitions invite the viewer to read a personality into a small set of rules.


Implementation in Brief#

Layer Choice & Rationale
Framework Next.js 14, App Router – static export, zero backend needed
State & I/O React hooks + localStorage
Art Pipeline In-code SVG sprites (shapeRendering="crispEdges")
Styling Tailwind; font VT323 for gentle CRT nostalgia
Hosting Static files on GitHub Pages

Clothing, behaviour and scenery are possible additions to the project.


Reading a personality into the rules#

Pixl is a small experiment in making a handful of rules visible. The interesting question is how much personality a clock, changing stats and a few sprites can suggest—and which interactions make those rules clear to the person playing.

Pixl itself

Footnotes

  1. Using shapeRendering="crispEdges" forces the browser to snap edges to the pixel grid, preventing the antialias blur that would otherwise undermine the retro aesthetic. ↩

  2. The hierarchy here is a design metaphor for choosing an animation: hunger and fatigue take priority over mood. It is a set of rules for a toy, rather than a psychological model. ↩