The atan2() function calculates the angle between two positions. The angle it calculates can be used to rotate a shape toward something. In this example, the eyes rotate to look at the cursor.
Contributors: Malay Vasa, Kenneth Lim, Miriam Nadler, Alex Yixuan Xu, Animesh Sinha, Katie, Caleb Foss, Darren Kessner
Modified from Arctangent.
Originally ported from the Processing example Arctangent.
Aim is licensed under CC BY-NC-SA 4.0.
Related Examples

A point on the unit circle, together with the corresponding sine and cosine values on their graphs.
Sine and Cosine
Animate circular, back and forth, and wave motion.

Two eyes on a black background.
Aim
Rotate toward a point.

Rainbow ring made up of triangles whose vertices lie on two concentric circles.
Triangle Strip
Split a ring into triangles.