Skip to content

Instantly share code, notes, and snippets.

Created October 7, 2015 20:35
Show Gist options
  • Save anonymous/2d7cfdf8b6aa6fc06312 to your computer and use it in GitHub Desktop.
Save anonymous/2d7cfdf8b6aa6fc06312 to your computer and use it in GitHub Desktop.
Secret wave function
import math as mt
import numpy as np
def sine(t, rising_time=mt.pi):
return mt.sin(mt.pi * float(t) / rising_time)
def secret_wave(t, a, b):
r = (t + float(a) / 2) % (a + b)
t_prime = r - float(a) / 2
if r <= a:
return sine(t_prime, a)
else:
return sine(t_prime - float(a - b) / 2, b)
import matplotlib.pyplot as plt
x = np.arange(-10, 10, 0.1)
a, b = 4, 1
y = [secret_wave(t, a, b) for t in x]
plt.plot(x, y)
plt.axes().set_aspect('equal')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment