I'm working in JavaScript with HTML5 and the canvas. I have an object which is rotating at a certain speed, and I need the object's rotation to slow down gradually and the front of the object to stop at a specified angle. (I'm using radians, not degrees.) I have a variable to keep track of the angle which the object is facing, as it rotates.

How would I go about getting the object to come to rest, facing the direction I want it to?

Visualise a graph of rotation versus time that gradually drops to zero and notice there is an infinite number of ways of drawing such a graph. First, you'll have to specify how you want the angular velocity to decrease. Formulate a function ω(t) that equals the starting angular velocity (s) at t=0 and drops to zero eventually (t=T). Tune the variables to match the following criterium: ω(t) integrated over t from 0 to T equals the rotation yet to be covered. An example:

I want my angular velocity to decrease in a linear fashion, i.e.: ω(t) = s + a t. To find T, we solve: s + a T = 0, ergo: T = -s/a. Integrating yields that the angle covered in this gradually decelerated rotation equals -½ s² / a. Solving for a gives us the desired angular velocity at every timestep, which we can numerically integrate as we go to find the current angle, or do this in advance to obtain a function angle of time which we can use directly.