You'll want to use scenery-phet.ParametericSpringNode. I was the author of the Hooke's Law sim, and scenery-phet.ParametericSpringNode. I'm not as familiar with the Masses and Springs simulation, but I see that it also uses ParametericSpringNode.
I would start by familiarizing yourself with ParametericSpringNode. The scenery-phet repository has a very nice demo, the "Spring" screen, which looks like the screenshot below. Each of the sliders in this demo controls a Property of the spring. To animate the spring, you'll probably be most interested in xScaleProperty.
Next, I would look at the mass-and-springs repository, to see how it animates xScaleProperty. Got to masses-and-springs.OscillatingSpringNode, and search for xScaleProperty. If you need more help with masses-and-springs (e.g. how the animation works), feel free to ask again in this form, and we'll try to get someone who is familiar with that sim to respond.
I hope this helps!
Chris Malley
PixelZoom, Inc.