import numpy as np
import matplotlib.pyplot as plt
from matplotlib.collections import LineCollection
t = np.linspace(0, 2 * np.pi, 1000)
x = 16 * np.sin(t)**3
y = 13 * np.cos(t) - 5 * np.cos(2 * t) - 2 * np.cos(3 * t) - np.cos(4 * t)
colors = plt.cm.rainbow(np.linspace(0, 1, len(t)))
points = np.array([x, y]).T.reshape(-1, 1, 2)
segments = np.concatenate([points[:-1], points[1:]], axis=1)
lc = LineCollection(segments, colors=colors, linewidth=2)
plt.figure(figsize=(6, 6))
plt.gca().add_collection(lc)
plt.gca().set_facecolor('black')
plt.fill(x, y, 'r', alpha=0.2)
plt.title("Heart Shape")
plt.axis('equal')
plt.axis('off')
plt.show()