Generation of spatial patterns through cell polarity switching