- Calculates the sine of an angle.
- angle
- The angle, using a full circle range of 0.0-1.0 measured clockwise (0.0 to the right).
The sin()
function calculates the sine of an angle.
PICO-8 uses an input range of 0.0 to 1.0 to represent the angle, a percentage of the unit circle. Some refer to these units as "turns". For instance, 180° or π (3.14159) radians corresponds to 0.5 turns in PICO-8's representation of angles. In fact, for fans of τ (tau), it's just a matter of dropping τ from your expression.
Important: PICO-8 measures the angle in a clockwise direction on the Cartesian plane, with 0.0 to the right, 0.25 downward, and so on. This is inverted from the convention used in traditional geometry, though the inversion only affects sin()
, not cos()
.
The inversion is useful because PICO-8's screen (like most graphics engines) uses inverted y coordinates: an increase in y goes downward. Many uses of sin()
would need to be inverted anyway, so PICO-8 does it by convention.
(The clockwise direction of the angle is equivalent to going counterclockwise and negating sin()
. This is how it is described in the official documentation.)
Examples Edit
for t=0,1,0.125 do print('sin('..t..') = '..sin(t)) end
prints:
sin(0) = 0 sin(0.125) = -0.7071 sin(0.25) = -1 sin(0.375) = -0.7071 sin(0.5) = 0 sin(0.625) = 0.7071 sin(0.75) = 1 sin(0.875) = 0.7071 sin(1) = 0