print('\n'.join([''.join([('Love'[(x-y)%4]if((x*0.05)**2+(y*0.1)**2-1)**3-(x*0.05)**2*(y*0.1)**3<=0else' ')for x inrange(-30,30)])for y inrange(15,-15,-1)]))
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
x = np.linspace(-2,2,100)
y = np.linspace(-2,2,100)
X, Y = np.meshgrid(x, y)
Z = X**2+(5*Y/4- np.sqrt(abs(X)))**2-1
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(X, Y, Z, color='red')
plt.show()
创意扩展:交互式爱心效果
使用pygame创建可交互的爱心动画
实现鼠标跟随效果和颜色变化
import pygame
import math
import random
pygame.init()
screen = pygame.display.set_mode((800,600))
clock = pygame.time.Clock()
running =Truewhile running:for event in pygame.event.get():if event.type== pygame.QUIT:
running =False
screen.fill((0,0,0))
mx, my = pygame.mouse.get_pos()for i inrange(0,628,5):
x =16* math.sin(i/100)**3
y =13* math.cos(i/100)-5* math.cos(2*i/100)-2* math.cos(3*i/100)- math.cos(4*i/100)
pos =(int(x*10+ mx),int(-y*10+ my))
pygame.draw.circle(screen,(random.randint(200,255),0,0), pos,2)
pygame.display.flip()
clock.tick(60)
pygame.quit()