To earn purple stars you must complete the challenges on levels that are marked with a star. Challenge goals are different at each level.
For example: destroy a particular number of orange marbles, create a couple of color bombs, collect a certain number of flowers, etc. Once the level starts, a challenge will appear on the screen right at the beginning. At any time, on the left side of the screen, you have a bar where you can see what needs to be done in order to get the purple star.
The purple star can be used as a rewind.
If you find yourself in a tricky situation of losing a level, you can use the purple star to rewind the chain and continue the game.