<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Havey Bachand</title>
    <description>The latest articles on DEV Community by Havey Bachand (@havey_bachand_04f8879200a).</description>
    <link>https://dev.to/havey_bachand_04f8879200a</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4221366%2F44b12957-e699-4b7a-a940-537a91617457.png</url>
      <title>DEV Community: Havey Bachand</title>
      <link>https://dev.to/havey_bachand_04f8879200a</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/havey_bachand_04f8879200a"/>
    <language>en</language>
    <item>
      <title>How keystroke-reactive animation works in a desktop pet</title>
      <dc:creator>Havey Bachand</dc:creator>
      <pubDate>Sun, 15 Nov 2026 09:10:36 +0000</pubDate>
      <link>https://dev.to/havey_bachand_04f8879200a/how-keystroke-reactive-animation-works-in-a-desktop-pet-4k19</link>
      <guid>https://dev.to/havey_bachand_04f8879200a/how-keystroke-reactive-animation-works-in-a-desktop-pet-4k19</guid>
      <description>&lt;p&gt;A desktop pet that "reacts to typing" sounds like a sprite problem: draw a look-up frame, play it on &lt;code&gt;keydown&lt;/code&gt;. That only works in a normal app.&lt;/p&gt;

&lt;p&gt;A desktop pet is not a normal app. If the design is working, its window almost never has focus. The user is typing into a browser or an editor. Your process sits in a transparent, click-through window on top of that work, and it must not steal focus just to notice the typing. The interesting problem is upstream of animation: get a trustworthy "the human is typing" signal, then turn it into motion that feels alive instead of twitchy.&lt;/p&gt;

&lt;p&gt;I ran into this while building a &lt;a href="https://desktopcat.com/download" rel="noopener noreferrer"&gt;desktop cat for Mac and Windows&lt;/a&gt;. What follows is the design, not a source dump — the app is closed source — but the constraints are the same for any companion that lives on the desktop all day.&lt;/p&gt;

&lt;h2&gt;
  
  
  You want presence, not keystrokes
&lt;/h2&gt;

&lt;p&gt;The first rule is privacy, and it also simplifies the technical work. The pet does not need to know &lt;em&gt;which&lt;/em&gt; keys were pressed, or to build a log of what was typed. It needs a presence bit: is the person actively using the keyboard right now?&lt;/p&gt;

&lt;p&gt;That sounds like a small distinction. It is not. A hook that records key identities is a keylogger with a cat painted on it. A hook that only updates "last typing activity was N milliseconds ago" is the only version I am willing to ship. Mouse tracking follows the same rule. On macOS the app asks for permission so the cat can react to clicks and cursor position; the download page states those coordinates are used only for animation, and are never stored or sent anywhere. The app has no usage telemetry.&lt;/p&gt;

&lt;p&gt;If you are building something in this family, make the data model match the promise. Keep a timestamp, or a short decaying "typing energy" value. Do not keep a buffer of keys.&lt;/p&gt;

&lt;h2&gt;
  
  
  The signal has to come from the OS, not from your window
&lt;/h2&gt;

&lt;p&gt;Because the pet window is unfocused on purpose, toolkit events will not save you. You need some form of OS-level input observation that works while other applications are in front.&lt;/p&gt;

&lt;p&gt;The exact API differs by platform, and so do the permission prompts. macOS is blunt: global mouse tracking shows a system dialog, and people are right to read it carefully. Windows is less theatrical, which is not an excuse to collect more than you need. In both cases I treat the hook as a narrow sensor. It answers "was there keyboard activity?" and "where is the cursor?" It does not get to start a side channel.&lt;/p&gt;

&lt;p&gt;Two implementation details matter more than the hook itself:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Coalesce, do not enqueue.&lt;/strong&gt; A fast typist can produce more events than you want to wake up for. Fold them into a single "activity seen" update on an animation-friendly interval. I would rather be a few milliseconds late than wake the process on every repeat key.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hysteresis.&lt;/strong&gt; One key should not yank the cat out of a deep sleep into a full typing cycle and back again. I use a short start delay so a single accidental press is ignored, a sustain window while keys keep arriving, and a longer fade after the last key so the cat can look, settle, and only later go back to roaming or napping.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The state machine is closer to a street cat than to a progress spinner:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;idle / nap  --(keys for ~N ms)--&amp;gt;  notice
notice      --(keys continue)--&amp;gt;   watch / "you are busy"
watch       --(quiet for ~M ms)--&amp;gt; settle
settle      --(still quiet)--&amp;gt;     roam or nap
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The timings are a taste question. Too tight, and the cat looks nervous. Too loose, and it fails to notice you.&lt;/p&gt;

&lt;h2&gt;
  
  
  Animation is a reaction, not a transcript
&lt;/h2&gt;

&lt;p&gt;Once you have a stable "typing" state, the sprite work is almost secondary — which is good, because you can keep the loop cheap.&lt;/p&gt;

&lt;p&gt;I do not try to match animation to the rhythm of individual keys. That costs CPU and makes the character chatter when you hold backspace. The pet gets a small set of reactions: glance up, watch, maybe a short fidget, then settle. Narrow randomness helps, so the same burst of typing does not always play the same two frames.&lt;/p&gt;

&lt;p&gt;Cursor position is a second, quieter input. If the pointer is far away and the user is typing, looking toward the focused window is enough. If the pointer passes close to the cat, that is more like being walked up to than being ignored. Mixing the two signals keeps the behavior from feeling like an on/off lamp.&lt;/p&gt;

&lt;h2&gt;
  
  
  Do not let the sensor keep the process hot
&lt;/h2&gt;

&lt;p&gt;A pet that is charming for five minutes and warm on your lap after an hour has failed. The keystroke path has to respect the same budget as everything else.&lt;/p&gt;

&lt;p&gt;When no keys have arrived and the cursor is still, there is nothing to do. Arm a "someone typed" wakeup, then go back to a slow idle. Do not run a 16 ms timer just in case. When the cat is asleep, a lower animation rate is fine.&lt;/p&gt;

&lt;p&gt;This is also why I use Tauri as the shell rather than shipping a full browser runtime for a sprite. The runtime is only part of the cost. The rest is discipline: no redraws when nothing changed, no hidden windows, no extra work in the input path.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I still do not know
&lt;/h2&gt;

&lt;p&gt;I have not solved this, only shipped a version I can leave running. Multi-monitor setups, full-screen presentations, and "the cat noticed my password manager" unease are still live issues — the last one is why the presence-only model matters. If you have built a global-input animation loop that stays honest and cheap, I would like to hear what you settled on for the start and fade timings.&lt;/p&gt;

</description>
      <category>tauri</category>
      <category>animation</category>
      <category>macos</category>
      <category>windows</category>
    </item>
    <item>
      <title>Compressing and resizing GIFs entirely in the browser</title>
      <dc:creator>Havey Bachand</dc:creator>
      <pubDate>Fri, 13 Nov 2026 03:42:07 +0000</pubDate>
      <link>https://dev.to/havey_bachand_04f8879200a/compressing-and-resizing-gifs-entirely-in-the-browser-2jd7</link>
      <guid>https://dev.to/havey_bachand_04f8879200a/compressing-and-resizing-gifs-entirely-in-the-browser-2jd7</guid>
      <description>&lt;h1&gt;
  
  
  Compressing and resizing GIFs entirely in the browser
&lt;/h1&gt;

&lt;p&gt;Chat apps still treat GIF as a first-class attachment, and they still enforce hard upload limits. The usual fix is to send the file to an online compressor. That works, but it is a lot of trust for a bug-report clip or a meme you would rather keep on the device.&lt;/p&gt;

&lt;p&gt;You do not need a server for this. Decode the palettized frames into RGBA, transform them, and encode again — with GIF's 10-millisecond delay precision — and the whole job can stay inside a browser tab.&lt;/p&gt;

&lt;h2&gt;
  
  
  Keep the UI thread out of it
&lt;/h2&gt;

&lt;p&gt;The practical constraint is memory and main-thread jank, not network. Expanding a large, many-frame GIF into full canvases can allocate hundreds of megabytes. I run the work in a module Web Worker: the page posts a &lt;code&gt;File&lt;/code&gt;, receives progress events, and gets back a &lt;code&gt;Uint8Array&lt;/code&gt; that becomes an object URL.&lt;/p&gt;

&lt;p&gt;On the way in, &lt;a href="https://github.com/matt-way/gifuct-js" rel="noopener noreferrer"&gt;gifuct-js&lt;/a&gt; parses the file and I composite every frame onto a full-size canvas, honoring disposal 2 (clear the dirty rectangle) and disposal 3 (restore the saved canvas). After that, every frame is a complete RGBA buffer, which makes resize, crop, and frame-dropping straightforward.&lt;/p&gt;

&lt;p&gt;Two guardrails matter on phones. First, I cap total pixels across all frames — 60 million in this pipeline, about 240 MB of RGBA — and, if a file is over budget, downscale while decoding. Second, I clamp frame delays to a 20 ms minimum. Many browsers, and clients such as Discord and Slack, treat a delay under 20 ms as 100 ms. Honor a file's 10 ms delays when speeding a clip up, and the export can play &lt;em&gt;slower&lt;/em&gt; than you intended.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="no"&gt;MIN_SAFE_DELAY&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// shorter delays often play as 100 ms&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;roundDelay&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ms&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;MIN_SAFE_DELAY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ms&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When a speed change would push a frame below that floor, I merge it into a neighbor and carry the leftover time.&lt;/p&gt;

&lt;h2&gt;
  
  
  Encoding only what changed
&lt;/h2&gt;

&lt;p&gt;Encoding uses a vendored copy of &lt;a href="https://github.com/mattdesl/gifenc" rel="noopener noreferrer"&gt;gifenc&lt;/a&gt;: a per-frame palette of 2–256 colors, then LZW. Opaque animations get a useful extra step. After the first full frame, each later frame is compared against the pixels already on screen — the quantized result, not the pre-palette source, so rounding errors do not accumulate. Only the bounding box of changed pixels is written. Unchanged pixels inside that box are marked transparent so the previous frame shows through. If nothing changed at all, I write a 1×1 transparent pixel just to preserve the delay.&lt;/p&gt;

&lt;p&gt;Animations that already contain transparency cannot use that trick safely. They are written as full frames with disposal 2, so holes stay holes even if the file grows. A &lt;code&gt;diffTolerance&lt;/code&gt; lets nearby RGB values count as unchanged: 0 is lossless deduplication; higher values trade a little smearing for a smaller dirty rectangle.&lt;/p&gt;

&lt;h2&gt;
  
  
  Resize is not a single algorithm
&lt;/h2&gt;

&lt;p&gt;Shrinking and enlarging need different filters. When the output is smaller or the same size, I use area averaging with premultiplied alpha so thin transparent edges do not go muddy. When enlarging, I use bilinear sampling. A square crop is a centered cut with no movable box — fine for avatars, easy to clip a waving hand if you skip the loop preview. Changing dimensions does not guarantee a smaller file, which is why a compressor and a resizer should be different tools: one asks for a width (128–800 px presets, or an exact size up to 4,000 px), the other asks for a byte target.&lt;/p&gt;

&lt;h2&gt;
  
  
  A ladder, not a single knob
&lt;/h2&gt;

&lt;p&gt;To aim at 512 KiB or 1 MiB, I do not expose a vague “quality 70.” I walk a fixed ladder and stop at the first encode that fits: fewer colors (256 down to 32), a smaller scale (100% down to 30%), then fewer frames (keep every frame, then every second, third, or fourth), while also raising the inter-frame tolerance. Dropped frames donate their delay to the frame that is kept, so the decoded duration stays the same even if the motion gets choppier.&lt;/p&gt;

&lt;p&gt;If no step fits, the tool returns the smallest candidate and says so. A 30%-wide, 32-color, every-fourth-frame export of a long, grainy clip can still miss a 256 KiB budget. Trim the clip or resize to the display size first — smaller dimensions usually look better than heavier color reduction. Flat colors also compress far better than film grain or camera shake.&lt;/p&gt;

&lt;p&gt;The same worker converts WebP. Still images go through &lt;code&gt;createImageBitmap&lt;/code&gt;. Animated WebP needs the &lt;code&gt;ImageDecoder&lt;/code&gt; API so every frame is recovered; I also inspect the RIFF chunks for &lt;code&gt;ANIM&lt;/code&gt; / &lt;code&gt;ANMF&lt;/code&gt; (or the VP8X animation flag). If the file is animated and the browser cannot decode frames, conversion stops rather than exporting only the first frame.&lt;/p&gt;

&lt;p&gt;If the destination accepts MP4, compare a video export as well. Google's &lt;a href="https://web.dev/articles/replace-gifs-with-videos" rel="noopener noreferrer"&gt;notes on replacing GIFs with video&lt;/a&gt; are a good reminder that GIF is a convenience format, not a compression format.&lt;/p&gt;

&lt;p&gt;I wired this pipeline into the free browser tools on &lt;a href="https://imagetogif.app" rel="noopener noreferrer"&gt;ImageToGif&lt;/a&gt;, including a &lt;a href="https://imagetogif.app/gif-compressor" rel="noopener noreferrer"&gt;GIF compressor&lt;/a&gt; that aims at a size you choose. The file never leaves the tab, there is no account, and nothing adds a watermark. I would like to hear if you have hit a 10 ms delay that plays as 100 ms.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>gif</category>
      <category>showdev</category>
    </item>
    <item>
      <title>Preview a tattoo in the browser: client-side canvas compositing without uploading your photo</title>
      <dc:creator>Havey Bachand</dc:creator>
      <pubDate>Sun, 08 Nov 2026 01:17:06 +0000</pubDate>
      <link>https://dev.to/havey_bachand_04f8879200a/preview-a-tattoo-in-the-browser-client-side-canvas-compositing-without-uploading-your-photo-6ob</link>
      <guid>https://dev.to/havey_bachand_04f8879200a/preview-a-tattoo-in-the-browser-client-side-canvas-compositing-without-uploading-your-photo-6ob</guid>
      <description>&lt;p&gt;Body photos are personal. If you are only trying a design on your forearm or wrist, there is no good reason that picture should leave the device just to draw one image on top of another.&lt;/p&gt;

&lt;p&gt;A tattoo try-on preview is mostly 2D compositing: a body photo as the base layer, a design (ideally with a transparent background) as the overlay, then pan, scale, rotate, and opacity. The Canvas 2D API can do all of that locally.&lt;/p&gt;

&lt;h2&gt;
  
  
  The two-layer model
&lt;/h2&gt;

&lt;p&gt;Keep two images in memory: the body photo and the tattoo artwork. Draw the photo first, then draw the design with a transform:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;drawPreview&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;tattoo&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;scale&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;angle&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;opacity&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;clearRect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;canvas&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;width&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;canvas&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;height&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;drawImage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;canvas&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;width&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;canvas&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;height&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;save&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;translate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;rotate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;angle&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;scale&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;scale&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;scale&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;globalAlpha&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;opacity&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;drawImage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;tattoo&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;tattoo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;width&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;tattoo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;height&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;restore&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Pointer events update &lt;code&gt;x&lt;/code&gt; / &lt;code&gt;y&lt;/code&gt;. A slider updates &lt;code&gt;scale&lt;/code&gt;, &lt;code&gt;angle&lt;/code&gt;, or &lt;code&gt;opacity&lt;/code&gt;. Redraw on every change. That is enough for “move it, make it bigger, turn it a few degrees, and see how heavy the ink looks.”&lt;/p&gt;

&lt;p&gt;&lt;code&gt;globalAlpha&lt;/code&gt; is a preview control, not a prediction of healed ink. It helps someone compare a softer overlay with a stronger one; it does not tell you how dense a real tattoo will be.&lt;/p&gt;

&lt;h2&gt;
  
  
  Transparency and white backgrounds
&lt;/h2&gt;

&lt;p&gt;Design files work best as PNG/WebP with a real alpha channel. If someone uploads a design on a white background, a simple chroma-style pass (treat near-white pixels as transparent) is often enough to keep a paper-scan from covering the skin. It will not beat a proper transparent export, but it stops the preview from looking like a white sticker.&lt;/p&gt;

&lt;h2&gt;
  
  
  What this model cannot do
&lt;/h2&gt;

&lt;p&gt;A flat overlay cannot wrap around an ankle, follow the curve of a shoulder, or show how a design will look after healing. Perspective is whatever the photograph already has. If the photo is cropped too tightly, it also becomes hard to judge proportion against nearby landmarks (wrist, elbow, knuckles).&lt;/p&gt;

&lt;p&gt;Those limits are worth saying out loud. A browser preview is a conversation starter for you and a tattoo artist, not a stencil and not a promise.&lt;/p&gt;

&lt;h2&gt;
  
  
  Privacy by keeping pixels local
&lt;/h2&gt;

&lt;p&gt;Because the composition never needs a server, the photo and the design can stay in &lt;code&gt;File&lt;/code&gt; / &lt;code&gt;ImageBitmap&lt;/code&gt; objects and, if you want a short-lived draft, in the browser’s local storage. No account is required for the preview itself. That matters more for a body photo than for a typical screenshot app.&lt;/p&gt;

&lt;p&gt;If you want to try this kind of preview without writing the canvas code, I built &lt;a href="https://tattryon.com" rel="noopener noreferrer"&gt;TatTryOn&lt;/a&gt;: a free Classic simulator that runs in the browser (no sign-up; photos stay on your device), plus an optional AI tattoo generator when you want a new design to place. The preview is a flat overlay with blending, and it says so.&lt;/p&gt;

&lt;p&gt;Happy to talk through canvas gotchas — hit-testing a rotated overlay, exporting the before/after, or keeping large photos from choking mobile browsers — in the comments.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>showdev</category>
    </item>
    <item>
      <title>Design notes for building a desktop pet that stays out of your way</title>
      <dc:creator>Havey Bachand</dc:creator>
      <pubDate>Thu, 05 Nov 2026 07:53:08 +0000</pubDate>
      <link>https://dev.to/havey_bachand_04f8879200a/design-notes-for-building-a-desktop-pet-that-stays-out-of-your-way-376b</link>
      <guid>https://dev.to/havey_bachand_04f8879200a/design-notes-for-building-a-desktop-pet-that-stays-out-of-your-way-376b</guid>
      <description>&lt;p&gt;Desktop pets are a fun corner of desktop software: a small character lives on top of your windows, wanders around, and reacts to what you do. I work on DesktopCat, a free desktop cat for macOS and Windows, and here are a few design considerations that come up for any app of this kind.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. The pet must never get in the way
&lt;/h2&gt;

&lt;p&gt;A desktop pet lives on the screen all day, so it has to be unobtrusive. That means a transparent window, no stealing keyboard focus, and clicks passing through everywhere except on the character itself.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Keep it light
&lt;/h2&gt;

&lt;p&gt;Idle animation should cost almost no CPU or memory. A lightweight cross-platform shell (we use Tauri for the app) helps compared with shipping a full browser runtime, though sprite animation and window management are where most of the tuning goes.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Reactions make it feel alive
&lt;/h2&gt;

&lt;p&gt;Small touches matter more than complex AI: napping when you are idle, looking up when you type, letting you pet, feed and drag the cat. Random-but-believable behavior beats scripted loops.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Be honest about what is free
&lt;/h2&gt;

&lt;p&gt;DesktopCat itself and the default cat, Mochi, are free with no account needed. Optional extras (an official cats pass and a human-made custom cat from your own photos) are sold separately. The app is closed source.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try it
&lt;/h2&gt;

&lt;p&gt;macOS 13+ (Apple Silicon) and Windows 10/11 (x64): &lt;a href="https://desktopcat.com/download" rel="noopener noreferrer"&gt;https://desktopcat.com/download&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Feedback on behavior ideas for a desktop companion is very welcome in the comments.&lt;/p&gt;

</description>
      <category>desktop</category>
      <category>tauri</category>
      <category>macos</category>
      <category>windows</category>
    </item>
    <item>
      <title>How the "train window toy car becomes a real car" AI video trend works (and how to shoot a photo that works)</title>
      <dc:creator>Havey Bachand</dc:creator>
      <pubDate>Mon, 02 Nov 2026 02:12:04 +0000</pubDate>
      <link>https://dev.to/havey_bachand_04f8879200a/how-the-train-window-toy-car-becomes-a-real-car-ai-video-trend-works-and-how-to-shoot-a-photo-33db</link>
      <guid>https://dev.to/havey_bachand_04f8879200a/how-the-train-window-toy-car-becomes-a-real-car-ai-video-trend-works-and-how-to-shoot-a-photo-33db</guid>
      <description>&lt;p&gt;If you've scrolled short-video feeds lately you've probably seen it: a tiny toy car sits on the windowsill of a moving train, the train dives into a dark tunnel, and when it comes out the same car is full-size, driving down an open road. It looks like a practical effect, but almost every version you see is image-to-video AI.&lt;/p&gt;

&lt;p&gt;I built a small tool around this one effect, so here's what I learned about why it works and what makes a good source photo.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why the tunnel matters
&lt;/h2&gt;

&lt;p&gt;Image-to-video models are good at short, continuous motion and bad at big scale changes inside a single unbroken shot. The tunnel solves that. The frame goes dark for a beat, which gives the model a natural "cut" where the scale of the car can jump from miniature to life-size without the viewer seeing the morph. The train window frame also helps: it's a strong, stable composition that keeps the model from drifting.&lt;/p&gt;

&lt;p&gt;So the shot is really three beats:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Toy-scale car on the windowsill, landscape moving outside.&lt;/li&gt;
&lt;li&gt;Tunnel darkness (the transition).&lt;/li&gt;
&lt;li&gt;The same car, full-size, on the road.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  What makes a good input photo
&lt;/h2&gt;

&lt;p&gt;After a lot of test renders, these mattered most:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;One car, clearly visible.&lt;/strong&gt; Rear three-quarter angle works best because it reads well both as a toy and as a real car.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Daylight, simple background.&lt;/strong&gt; Busy parking lots confuse the identity of the car between beat 1 and beat 3.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No people, no readable license plates.&lt;/strong&gt; Faces and plates get mangled and are a privacy issue anyway.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Not too cropped.&lt;/strong&gt; The model needs the whole silhouette to keep the car consistent across the tunnel.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Output format choices
&lt;/h2&gt;

&lt;p&gt;For this kind of clip I settled on ~15 seconds, 720p, 9:16 vertical, with generated ambient sound (train, engine, road). Vertical because that's where the trend lives, and sound because a silent clip of a train feels wrong immediately.&lt;/p&gt;

&lt;h2&gt;
  
  
  The tool
&lt;/h2&gt;

&lt;p&gt;If you want to try the effect without writing prompts, I put it at &lt;a href="https://trainwindowai.com" rel="noopener noreferrer"&gt;TrainWindowAI&lt;/a&gt;: upload one car photo and you get the MP4. It's a one-time $8.99 per video, no subscription, and failed renders return the credits. It runs on Seedance 2.0 Mini.&lt;/p&gt;

&lt;p&gt;Happy to answer questions about the prompt structure or the photo tips in the comments.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>video</category>
      <category>generativeai</category>
      <category>showdev</category>
    </item>
  </channel>
</rss>
