If your browser both supports the Web Workers API and the OffscreenCanvas interface, Robots are now dancing smoothly in their own separate OS-managed CPU thread.
Workers require a separate JS file, but I wanted all the code be packed in a single html file, all in the JS panel on CodePen. Credits to Roman Liutikov for his nice inliner function trick.
In my example worker code is all contained in the 'theLastExperience' function. Fallback to running from the main thread is achieved with no code duplication.
Thanks to the OffScreenCanvas interface, all canvas painting code can now be handled from the worker code directly. This is really convenient.
I haven’t performed extensive testing. It's working just fine in Chrome (as usual). Tested from my iPhone, Firefox and Edge on W10, Robots running in the main thread.
Feedback is appreciated :-)