脚本代码:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import time
# 打印爱心图案
def print_love():
myData = "love"
for char in myData.split():
allChar = []
for y in range(12, -12, -1):
lst = []
lst_con = ''
for x in range(-30, 30):
formula = ((x * 0.05) ** 2 + (y * 0.1) ** 2 - 1) ** 3 - (x * 0.05) ** 2 * (y * 0.1) ** 3
if formula <= 0:
lst_con += char[(x) % len(char)]
else:
lst_con += ' '
lst.append(lst_con)
allChar += lst
print('\n'.join(allChar))
time.sleep(1)
if __name__ == '__main__':
print_love()
运行结果:
脚本代码:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import matplotlib.pyplot as plt
import numpy as np
import time
# 打印爱心3D图案
def print_love3D():
start = time.time()
x_lim, y_lim, z_lim = np.linspace(-10, 10, 520), np.linspace(-10, 10, 520), np.linspace(-10, 10, 520)
X_points, Y_points, Z_points = [], [], []
for x in x_lim:
for y in y_lim:
for z in z_lim:
if (x**2+(9/4)*y**2+z**2-1)**3-(9/80)*y**2*z**3-x**2*z**3<=0:
X_points.append(x)
Y_points.append(y)
Z_points.append(z)
end = time.time()
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(X_points, Y_points, Z_points, s=20, alpha=0.5, color="red")
plt.show()
print(end-start)
if __name__ == '__main__':
print_love3D()
运行结果(需要等待一段时间):
如果您觉得文章还不错,请 点赞、分享、在看、收藏 一下,因为这将是我持续输出更多优质文章的最强动力!
如果对python自动化测试、web自动化、接口自动化、移动端自动化、面试经验交流等等感兴趣的测试人,可以 点我自行获取…