We use cookies and other tracking technologies to improve your browsing experience on our website, to show you personalized content and targeted ads, to analyze our website traffic, and to understand where our visitors are coming from.
⚠️
GDPR & Cookie Policy Notice
In accordance with data protection regulations; the use of mandatory cookies is required for the core functions of our website to operate, ensure data security, and perform analytics. If you reject the use of cookies, it is not possible to benefit from the services on our website due to technical limitations and data synchronization interruptions. You must consent to the use of cookies to access the content on our site.
An Intruder on the Desktop: Virtual Cat and Mouse Chase Application with Python
It all started when my sister showed me a video she was watching while taking a break at work. In the video, there was a cute virtual cat animation following the cursor with smooth focus on the desktop. When she threw out the question, “Can we make this for our computers?”, as a software developer, it was impossible not to roll up my sleeves.
The result is a virtual cat simulation that tirelessly chases a large white ball attached to the tip of your mouse across the screen. It turned out to be a completely open-source and fun project, but it’s worth giving a small warning right from the start: the presence of a digital cat constantly trying to catch your cursor on the screen might make it a bit difficult to focus. Also, a personal note from me: it is strictly not recommended to install and use it on work computers!
Figure 1: The Virtual cat chasing the white ball at the tip of the cursor on the desktop.
The Logic Behind the Project and the Development Process
Ensuring that a virtual character on the screen reacts to the user’s mouse movements in a real-time and smooth manner was the most enjoyable part of the project. If the cat’s movement consisted solely of teleporting to the coordinates of the mouse, all the naturalness would be lost.
Dynamic Tracking Algorithm
The acceleration, deceleration, and turning angles exhibited by the cat as it runs toward the large white ball at the tip of the mouse are based on a mathematical tracking algorithm. The fact that the cat speeds up when you suddenly pull the mouse away, and slows down to a stop as it approaches the cursor, adds an organic feel to the simulation. I managed to build this smooth movement structure by utilizing Python’s visualization and interface capabilities.
The Power of Open Source and the GitHub Family
I shared the code completely open-source so that the project can be developed by anyone, new movement animations can be added to the cat, or the tracked object can be customized. You can access the raw state and architecture of the code directly through the GitHub repository.
You don’t need to set up a Python environment and wrestle with libraries to try the project on your computer. I have prepared a compiled version of the application for those who want to welcome a virtual pet partner directly to their desktop without getting into technical details.
You can download the executable file with the .exe extension directly from the link below and launch the game with a single click:
(It’s worth reminding you again; if you don’t want your boss or colleagues coming up behind you and seeing a cat chasing a white ball on the screen, keeping this fun for your personal computers at home would be a wiser engineering decision.)
For Developers: What’s Under the Hood?
If you want to get into the kitchen of the work, change the cat’s speed parameters, or integrate another object instead of the white ball, you can start by cloning the Python project. The basic requirements are quite standard:
Optimizations were applied in the project to capture screen coordinates instantly and to draw the cat figure smoothly even at high frame rates (FPS). In order to prevent it from unnecessarily fatiguing the processor (CPU) while running in the background and slowing down your computer to hinder your work, the loop intervals were meticulously optimized.
Conclusion
Starting with inspiration from a small video frame, this tiny simulation turned into a sweet project that makes the desktop a bit more fun. You can also fork the code to bring new mechanics to the project, and share your experiences with your desktop’s new guest with me via GitHub, LinkedIn, and social media!