I was looking at the source and it appeared there was special handling on the mousemove event. I also had to introduce timeouts, otherwise it wouldn't work (not entirely sure why). So was being safer since I didn't want this to become a time sink :D
Funny thing: this feels "realistic" because it’s not perfect physics. A perfectly simulated Hooke's law spring actually looks fake and too stiff. But if you let the animation wobble a bit more and slow down the damping, our brain reads it as weight and squishiness.
Hooke's law only accounts for the force the spring applies, not the mass of the spring itself. Once you have to account for the mass of the spring, how that mass distribution changes as the string stretches & compresses, and how that alters the momentum it quickly loses its simplicity. That's far too difficult to do by hand, but it's what the real world does so I'd rather say that Hooke's law is a first-order approximation of spring force, not a perfect law for describing linear spring behavior.
> this feels "realistic" because it’s not perfect physics. A perfectly simulated Hooke's law spring
Confused. Perfect physics means perfectly simulating reality, not perfectly simulating an unreal idealized formula. Are you saying Hooke's law doesn't feel realistic or are you saying a simulator for a realistic spring doesn't feel realistic?
In reality, nothing is perfect. Materials are never 100% one material. Rustness is imperfection, the weight and material of the ball, and the place it's attached are also consideration points, how firmly it is attached, and with which material. A "perfect" simulation of the spring itself would have to consider all these variables, and they almost never do.
And even if you somehow included "everything" with the "perfect" equations, you'll end up with a lot of stuff which does not have a good closed form solution anyways and good luck getting that running (e.g. the dynamics around the air resistance/sound generation) via approximations both accurate enough that it looks better than "faking it" and fast enough that it's actually usable interactively.
This leads to what GP was saying: many just cut things off at "Hooke's law simulates a spring, so I'll use that, but the rest is a bit too much to fit so I won't do it" but "Hooke's law simulates a spring but adding a bit of not-physics based fluff approximates all the rest" actually gives far superior results even though it doesn't only use perfect physics equations as the former did.
Elasto Mania is a great game from decades ago (but still for sale!) that exploits this fact to a hilarious extent. You control a motor bike with excessively wobbly physics making all kinds of stunts possible (and necessary, to complete the levels) that are spectacular and surprising.
Wait. Is Jelly Car basically a rethinking of this? I never managed to have the elasto games, but looking at the trailer, there’s a lot of similarities.
Hooke's law is what's not not perfect physics, but an idealized version of a spring. No real spring (that we'd recognize as a spring) actually obeys it perfectly, because there is damping and friction and a bunch of things that Hooke's law does not factor in.
To get somewhat more realistic model of a spring, you a damping term, which turns it into an ODE[1].
This takes me back a few years when the first of my Uni friends had a baby, they spoiled him with so many toys that their lounge room was like an obstacle field where you had to be careful where to step, but despite all his toys the baby spent all his time while I was there playing with the door spring.
There's something therapeutic about door springs, that you just have to stop and play with it.
This reminds me why simple single-purpose web toys used to be so satisfying. No account, no onboarding, no "upgrade to pro" - just a thing that does one thing well. The world counter is a nice touch without being gamified into oblivion..
@gregasadetsky: you should make it social… you know, like, just because. Like I want to be able to send my sister my latest “Boing,” and see what she thinks of my technique.
Any consideration on sharing the unminified code? I was a bit curious to read through the code and it seems like such a shame to keep it obfuscated. From a quick perusal, it seems like the bulk of the code comes from howler.js (a sound library), and the core functionality is conveniently implemented below the mobile template.
That’s got to be one of the most satisfying things ever. The real device was a darling invention and this is a faithful recreation of the experience of being in time out in the 80s.
Having done a fair amount of audio physical modeling, I'll just say a synthesized version that's both fast and realistic would be possible but difficult. The difficulty is at least "it would make an impressive presentation at DAFx [1]", though I might be underestimating it, and it's more "you could make it your master's thesis at CCRMA [2]"
Ideal springs are a common, simple element in this field, but this kind of spring is very much not that.
You're probably better off improving the sample-based version by fading out the audio when necessary and using different samples based on the way it's triggered. If you have "ultra-dry" samples (maybe taken with a contact mic), you can add a convolution effect with a well-chosen impulse response, this will allow you to sharply cut off or adjust the audio and still have a natural-sounding tail.
I'm extremely grateful for this. My most deeply held secret is that I wish I could do this for a living - digitally modeling weird/beautiful objects/instruments and work on that forever haha. (And maybe make pedals out of them, I don't know)
If you don't mind humoring me (I'm quite the novice in this field), if I automated the recording of "all" possible positions for a spring (say I had a motor positioned in a way that would let me pull the spring in any polar direction), would that make modeling potentially easier?
There might be a "train an AI, here's 1000 recordings" angle, but I'm not necessarily interested in/asking about that.
Just strictly for modeling, would it help the modeling/R&D to have a lot of high sample rate recordings? Thanks a lot!
P.S. If you have a good intro to DSP class/book, I'd love to hear it. I know about a few, but a recc is always appreciated
I noticed that the boing sound gets deeper and lower with smaller-magnitude boings. Is the boing audio generated procedurally/realistically in response to the physics of the boing, or is just playing a premade boing sound effect that's dynamically pitch shifted?
TIL I don't know how to “unmute” my device anymore. My new-ish iPhone doesn't have a physical switch on the side and I can’t find it in the settings in the pulldown menu.
I just got an iPhone 17, and presumably because it inherited its Control Centre configuration from the 13 it replaces (which had a physical switch) the silent mode toggle was not present. Tap and hold in an empty space to edit the controls and add it in.
There seems to be a minor bug. When I switch tabs and come back, sometimes the spring is moving. Some times a small amount, and other times it appears to be streched to the max, and extending off the top and bottom of the screen, until it calms down.
I just wanted to write about a similar observation when using it in FireFox on Linux:
When wiggle the spring, keep the mouse inside the white area until it is at rest, press CTRL+u to see the source code, move the mouse to close the source code tab and close it - for some magical reason the spring is moving again for a little bit.
I wasn't hearing the sound initially so I thought it wasn't working in Firefox. Put the sound all the way up and boinged again. Made me jump out of my seat. Hilarious :-)
Make sure to unmute your device - either using the physical mute rocker on older iPhones, or by disabling Silent Mode (tap the bell in the Control Center)
I would love to, but iOS support doesn't seem possible - there's a trick [0] to make a hacky haptic vibration in javascript, but it doesn't work with the kinds of events here of drag&release. And (lame excuse, but) I don't have an Android phone to test the haptics to make sure they're semi realistic.
This might have to wait for the native app versions ha.
Yes! I've been toying with this project idea for a few ~months, trying out most of the models out there. The physics and the look of the spring would come out quite crazy looking, so I put it on the back burner.
This is not an ad, there's no affiliate link... but the physics & drawing code were one shot by the recently released Gemini 3 Pro. It was pretty incredible to see. Additional tweaks & boing counter server by Claude Code.
Anyone want to commission an AI to make a sequel called Boing or Krill where you have to choose between boinging the spring or playing a game of snake (drawn as a line of krill)?
(function () { function rateToDistance(rate) { const minR = 0.09; const maxR = 4.65; if (rate < minR) rate = minR; if (rate > maxR) rate = maxR; const t = (rate - minR) / (maxR - minR); return 400 * t; } function dispatchMouseEvent(type, target, clientX, clientY) { const event = new MouseEvent(type, { view: window, bubbles: true, cancelable: true, clientX, clientY, screenX: clientX + window.screenX, screenY: clientY + window.screenY, buttons: type === "mouseup" ? 0 : 1, button: 0, }); target.dispatchEvent(event); } const canvas = document.getElementById("canvas"); function triggerPull(distance) { const rect = canvas.getBoundingClientRect(); const startX = 266; const startY = 198; const startClientX = rect.left + startX; const startClientY = rect.top + startY; const endClientX = startClientX + distance; const endClientY = startClientY; return new Promise(resolve => { dispatchMouseEvent("mousedown", canvas, startClientX, startClientY); setTimeout(() => { dispatchMouseEvent("mousemove", canvas, endClientX, endClientY); setTimeout(() => { dispatchMouseEvent("mouseup", canvas, endClientX, endClientY); resolve(); }, 50); }, 50); }); } const semitones = 12; const notes = { G: Math.pow(4, -9 / semitones), A: Math.pow(4, -7 / semitones), B: Math.pow(4, -5 / semitones), C2: Math.pow(4, -4 / semitones), D2: Math.pow(4, -2 / semitones), E2: Math.pow(4, -0 / semitones), F2: Math.pow(4, 2 / semitones), G2: Math.pow(4, 4 / semitones), }; async function playWithPitch(rate) { const r = rateToDistance(rate); await triggerPull(r); } async function playScale() { const qrt = 200; const hlf = 400; const fll = 800; const pause = 15; const playNote = async (note, dur) => { await playWithPitch(note); await new Promise(res => setTimeout(res, dur)); }; const loop = async () => { await playNote(notes.E2, fll); await new Promise(res => setTimeout(res, pause)); await playNote(notes.E2, fll); await new Promise(res => setTimeout(res, pause)); await playNote(notes.E2, fll); await new Promise(res => setTimeout(res, pause)); await playNote(notes.C2, fll); await new Promise(res => setTimeout(res, pause)); await playNote(notes.G2, qrt); await playNote(notes.E2, fll); await new Promise(res => setTimeout(res, pause)); await playNote(notes.C2, fll); await new Promise(res => setTimeout(res, pause)); await playNote(notes.G2, qrt); await playNote(notes.E2, fll); await new Promise(res => setTimeout(res, pause)); await new Promise(res => setTimeout(res, pause)); await new Promise(res => setTimeout(res, pause)); }; await loop(); await loop(); await loop(); } playScale(); })();
(function () { function rateToDistance(rate) { const minR = 0.09; const maxR = 4.65; if (rate < minR) rate = minR; if (rate > maxR) rate = maxR; const t = (rate - minR) / (maxR - minR); return 400 * t; } function dispatchMouseEvent(type, target, clientX, clientY) { const event = new MouseEvent(type, { view: window, bubbles: true, cancelable: true, clientX, clientY, screenX: clientX + window.screenX, screenY: clientY + window.screenY, buttons: type === "mouseup" ? 0 : 1, button: 0, }); target.dispatchEvent(event); } const canvas = document.getElementById("canvas"); function triggerPull(distance) { const rect = canvas.getBoundingClientRect(); const startX = 266; const startY = 198; const startClientX = rect.left + startX; const startClientY = rect.top + startY; const endClientX = startClientX + distance; const endClientY = startClientY; return new Promise(resolve => { dispatchMouseEvent("mousedown", canvas, startClientX, startClientY); setTimeout(() => { dispatchMouseEvent("mousemove", window, endClientX, endClientY); setTimeout(() => { dispatchMouseEvent("mouseup", window, endClientX, endClientY); resolve(); }, 50); }, 50); }); } const semitones = 12; const notes = { G: Math.pow(4, -9 / semitones), A: Math.pow(4, -7 / semitones), B: Math.pow(4, -5 / semitones), C2: Math.pow(4, -4 / semitones), D2: Math.pow(4, -2 / semitones), E2: Math.pow(4, -0 / semitones), F2: Math.pow(4, 2 / semitones), G2: Math.pow(4, 4 / semitones), }; async function playWithPitch(rate) { const r = rateToDistance(rate); await triggerPull(r); } async function playScale() { const qrt = 200; const hlf = 400; const fll = 800; const pause = 15; const playNote = async (note, dur) => { await playWithPitch(note); await new Promise(res => setTimeout(res, dur)); }; const loop = async () => { await playNote(notes.C2, fll); await new Promise(res => setTimeout(res, pause)); await playNote(notes.D2, fll); await new Promise(res => setTimeout(res, pause)); await playNote(notes.G, hlf); await new Promise(res => setTimeout(res, pause)); await playNote(notes.D2, fll); await new Promise(res => setTimeout(res, pause)); await playNote(notes.E2, fll); await new Promise(res => setTimeout(res, pause)); await playNote(notes.G2, qrt); await playNote(notes.F2, qrt); await playNote(notes.E2, qrt); await new Promise(res => setTimeout(res, pause)); await playNote(notes.C2, fll); await new Promise(res => setTimeout(res, pause)); await playNote(notes.D2, fll); await new Promise(res => setTimeout(res, pause)); await playNote(notes.G, fll); await new Promise(res => setTimeout(res, pause)); await new Promise(res => setTimeout(res, pause)); await playNote(notes.G, qrt); await playNote(notes.G, qrt); await playNote(notes.A, qrt); await playNote(notes.C2, qrt); await new Promise(res => setTimeout(res, pause)); await playNote(notes.C2, qrt); await new Promise(res => setTimeout(res, pause)); }; await loop(); await loop(); await loop(); } playScale(); })();
It’s basically controlled sloppiness.
Confused. Perfect physics means perfectly simulating reality, not perfectly simulating an unreal idealized formula. Are you saying Hooke's law doesn't feel realistic or are you saying a simulator for a realistic spring doesn't feel realistic?
This leads to what GP was saying: many just cut things off at "Hooke's law simulates a spring, so I'll use that, but the rest is a bit too much to fit so I won't do it" but "Hooke's law simulates a spring but adding a bit of not-physics based fluff approximates all the rest" actually gives far superior results even though it doesn't only use perfect physics equations as the former did.
https://elastomania.com/
To get somewhat more realistic model of a spring, you a damping term, which turns it into an ODE[1].
[1] https://en.wikipedia.org/wiki/Mass-spring-damper_model
There's something therapeutic about door springs, that you just have to stop and play with it.
Time to recreate the classic: https://www.youtube.com/shorts/pTgJaJYHIAs
three.js, audio generating.
https://pastebin.com/FKyz20LG
Here is AI's implementation. https://jsfiddle.net/z0or7d2y/1/
In-memory ip address rate limiting.
Hosted and deployed on a ~$20 EC2 server using the open source tool I've been working on, https://disco.cloud/
We were at ~120 requests/second earlier and it took it on, no sweat.
EDIT: done! deploying.
wow ok that was a really good idea.
Ideal springs are a common, simple element in this field, but this kind of spring is very much not that.
You're probably better off improving the sample-based version by fading out the audio when necessary and using different samples based on the way it's triggered. If you have "ultra-dry" samples (maybe taken with a contact mic), you can add a convolution effect with a well-chosen impulse response, this will allow you to sharply cut off or adjust the audio and still have a natural-sounding tail.
[1] https://www.dafx.de/
[2] https://ccrma.stanford.edu/
If you don't mind humoring me (I'm quite the novice in this field), if I automated the recording of "all" possible positions for a spring (say I had a motor positioned in a way that would let me pull the spring in any polar direction), would that make modeling potentially easier?
There might be a "train an AI, here's 1000 recordings" angle, but I'm not necessarily interested in/asking about that.
Just strictly for modeling, would it help the modeling/R&D to have a lot of high sample rate recordings? Thanks a lot!
P.S. If you have a good intro to DSP class/book, I'd love to hear it. I know about a few, but a recc is always appreciated
try reloading again?
If I bend it right round to one side so the spring is curved I expect it to bounce round to the other side.
thanks!
https://codorex.com/shared/Ko4qJfnIKEjxDwqN2NAGueqWxYJFiz1F
That, or Settings -> Sounds & Haptics -> Silent Mode ?
Safari, Mac.
When wiggle the spring, keep the mouse inside the white area until it is at rest, press CTRL+u to see the source code, move the mouse to close the source code tab and close it - for some magical reason the spring is moving again for a little bit.
Just fixed, should be live soon.
There will also be no sound there if your phone is in Silence mode. However if Learning Synths works but not mine, then something else is happening.
Thanks!
Probably because I have Lockdown mode enabled, and/or NextDNS
https://www.decisionproblem.com/paperclips/
You can hate me and/or close the window at any point, friend...
but I agree - I have some other mono-site-ideas like these in mind, and I think that the accelerator could be very fun. thanks for the suggestion!
This might have to wait for the native app versions ha.
[0] https://progressier.com/pwa-capabilities/vibration-api
This is not an ad, there's no affiliate link... but the physics & drawing code were one shot by the recently released Gemini 3 Pro. It was pretty incredible to see. Additional tweaks & boing counter server by Claude Code.