Last active
July 2, 2024 08:52
-
-
Save secemp9/3a5936c2a1a252e09ffe3304790c68be to your computer and use it in GitHub Desktop.
This is a port of this tweet's work: https://x.com/naderi_yeganeh/status/1555529951650127872
This file contains hidden or 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 numpy as np | |
import matplotlib.pyplot as plt | |
# Define the parametric equations | |
def X(t): | |
return (4 / 9) * np.sin(2 * t) + (1 / 3) * (np.sin(t) ** 8) * np.cos(3 * t) + (1 / 8) * np.sin(2 * t) * ( | |
np.cos(247 * t) ** 4) | |
def Y(t): | |
return np.sin(t) + (1 / 3) * (np.sin(t) ** 8) * np.sin(3 * t) + (1 / 8) * np.sin(2 * t) * (np.sin(247 * t) ** 4) | |
# Create an array of t values from 0 to pi with more points | |
t = np.linspace(0, np.pi, 10000) | |
# Calculate x and y values | |
x = X(t) | |
y = Y(t) | |
# Create a color gradient from blue at the bottom to red at the top symmetrically | |
colors = np.concatenate([np.linspace(0, 1, len(t) // 2), np.linspace(1, 0, len(t) // 2)]) # Symmetric gradient | |
plt.figure(figsize=(8, 8)) | |
plt.scatter(x, y, c=colors, cmap='coolwarm', s=5.5) # Use coolwarm colormap for symmetric gradient | |
plt.axis('equal') | |
plt.axis('off') # Hide axes for a cleaner look | |
plt.title('Parametric Heart Curve', fontsize=16) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment