# Draw a character based sin wave
# https://docs.python.org/3/library/math.html#trigonometric-functions
# math.sin(x) -- Return the sine of x radians.
# This is not the neatest code in the world. It doesn't format that well when zero is varied.
import math
print('Sin(x)\n')
zero = 40
for x in range(0, 360, 5):
r = math.radians(x)
y = math.sin(r)
scaled = int((y + 1) * zero)
if abs(y) < 0.00001: # floating point numbers are not exact
print('{:03.0f} {:+1.4f}'.format(x,y), ' ' * scaled, '*')
elif y > 0:
print('{:03.0f} {:+1.4f}'.format(x,y), ' ' * zero, '.' + ' ' * (scaled - zero) + '*')
else:
print('{:03.0f} {:+1.4f}'.format(x,y), ' ' * scaled + '*' + ' ' * (zero - scaled - 1), '.')