To achieve these fun results, it is a simple matter of, given you have the right gear, re-focusing during a long exposure shot.
In either Manual or Shutter Priority mode, set the exposure to between 1 to 2 seconds (experiment a little).
Set the ISO to 100 to avoid over-exposure and, if in Manual mode, set the aperture to the the lowest f/ value available to start with and adjust upward as required.
Using a short to medium telephoto lens, start out-of-focus, press the shutter and quickly re-focus during the explosion.
Using a tripod helps to get smooth shapes but hand-holding can also work to create interesting effects.