It obeys the Snell's law: i.e. n_1 \sin\theta_1=n_2\sin\theta_2
Because each color has a different index of refraction (n) each color is refracted a different amount.

Are you talking about how to do it with computer program?