sin()
Calculates the sine of an angle.
sin() is useful for many geometric tasks in creative coding. The values returned oscillate between -1 and 1 as the input angle increases. sin() calculates the sine of an angle, using radians by default, or according to if angleMode() setting (RADIANS or DEGREES).
Examples

function setup()
size(100, 100)
describe('A white ball on a string oscillates up and down.')
end
function draw()
background(200)
-- Calculate the coordinates.
local x = 50
local y = 30 * sin(frameCount * 0.05) + 50
-- Draw the oscillator.
line(50, y, x, y)
circle(x, y, 20)
end

function setup()
size(100, 100)
background(200)
describe('A series of black dots form a wave pattern.')
end
function draw()
-- Calculate the coordinates.
local x = frameCount
local y = 30 * sin(x * 0.1) + 50
-- Draw the point.
point(x, y)
end

function setup()
size(100, 100)
background(200)
describe('A series of black dots form an infinity symbol.')
end
function draw()
-- Calculate the coordinates.
local x = 30 * cos(frameCount * 0.1) + 50
local y = 10 * sin(frameCount * 0.2) + 50
-- Draw the point.
point(x, y)
end
Syntax
sin(angle)
Parameters
| Parameter | |
|---|---|
| angle | Number: the angle, in radians by default, or according to angleMode() setting (RADIANS or DEGREES) |
Returns
Number: sine of the angle