Last active
February 15, 2020 08:33
-
-
Save onlinejudge95/e5aca593112522f96ac16c75d98c5c30 to your computer and use it in GitHub Desktop.
Late night gig
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 matplotlib.pyplot as plt | |
import numpy as np | |
x = np.arange(-2, 2, 0.00001) | |
upper = np.sqrt(1 - (abs(x) - 1) ** 2) | |
lower = np.arccos(1 - abs(x)) - np.pi | |
plt.plot(x, upper, color="darkred") | |
plt.plot(x, lower, color="darkred") | |
plt.fill(x, upper, color="crimson") | |
plt.fill(x, lower, color="crimson") | |
plt.subplots_adjust(0, 0, 1, 1) | |
plt.show() | |
plt.savefig("heart_two_dimensional.png") |
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
from mpl_toolkits.mplot3d import Axes3D | |
from matplotlib import pyplot as plt | |
import numpy as np | |
from skimage import measure | |
def cardioid(x,y,z): | |
return 320 * ((-x**2 * z**3 -9*y**2 * z**3/80) + (x**2 + 9*y**2/4 + z**2-1)**3) | |
n = 100 | |
x = np.linspace(-3, 3, n) | |
y = np.linspace(-3, 3, n) | |
z = np.linspace(-3, 3, n) | |
X, Y, Z = np.meshgrid(x, y, z) | |
volume = cardioid(X,Y,Z) | |
vertices, faces, _, _ = measure.marching_cubes_lewiner(volume, 0, spacing=(0.1, 0.1, 0.1)) | |
fig = plt.figure(figsize=(12,8)) | |
ax = fig.add_subplot(111, projection="3d") | |
ax.plot_trisurf(vertices[:, 0], vertices[:,1], faces, vertices[:, 2], cmap="Spectral", lw=1) | |
ax.view_init(15, -15) | |
ax.set_title(u"Made with ❤ (and Python)", fontsize=15) | |
plt.show() | |
plt.savefig("heart_three_dimensional.png") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
2D heart
3D heart