From the Super Mario Wiki, the Mario encyclopedia
Bowser Jr. initiates the shot by dribbling the ball in a B shape. The ball takes on a dull green glow, and Bowser Jr. tosses it straight up. He paints the ball in the air three times with his Magic Paintbrush, the third time hitting it into the basket with a trail of multi-colored paint behind it.
If executed outside the 3-pointer line, the visuals stay the same, but a teammate needs to complete the dunk.