跳到正文
网页珍奇柜Web Curio

追鼠标的小猫

oneko.js,adryd,2022 年

正在布展…

原作直展:这是 adryd 的原始作品,按 MIT 许可证收录(版本 5281d05)。oneko.js 和猫的精灵图原样展出,未作任何修改;本柜只加了一张宿主页,并打开了脚本自带的「不记住位置」选项,因为沙盒里不允许使用本地存储。 许可证全文 · 收录说明

它是怎么做的

  1. 第 1 步一个固定定位的 div,背景是精灵图(sprite sheet)。
  2. 第 2 步每 100ms 一步,朝鼠标方向移动固定距离。
  3. 第 3 步根据方向向量选择八方向奔跑帧,改变 background-position。
  4. 第 4 步距离足够近时进入闲置状态机:坐、挠、睡。

复刻配方

一段技术配方,可以直接交给 AI 编程助手,也可以自己照着写。想指定技术栈、位置和性能预算,就把它加入实现方案。

Draw or commission your own small pixel sprite sheet with run cycles for eight directions plus idle actions. Place a fixed 32x32 element with image-rendering: pixelated and step it on a slow interval (around 10 fps) toward the last pointer position by a constant distance. Choose the direction frame from the sign of dx and dy, alternate two frames for running, and when within a threshold switch to an idle timer that escalates from sitting to scratching to sleeping. Disable on touch devices and under reduced motion.

档案

能不能拿来用

原作以 MIT 许可开源:可以阅读源码学习,按许可证条款使用;在自己的项目里引用时保留原作者署名。

性能开销

视觉强度

实现难度

尺度为策展判断(1 到 5),用于比较和推荐。

核实记录:Repo page via gh api: MIT, created 2022-04-20, description 'Cat follow mouse real!'. No standalone demo URL (homepage empty).