Created
October 7, 2015 20:35
-
-
Save anonymous/2d7cfdf8b6aa6fc06312 to your computer and use it in GitHub Desktop.
Secret wave function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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