Phython-----绘制爱心

一、前言

        python 这款编程语言,充满了趣味性,而其的Time库的延展性更为丰富,我们可以将数学公式转换为编程语言来让其来进行绘制图形,快来和我一起去开启神秘的python大门吧!

二、绘制内容展示

1.在控制台打出  ''I ♥ U''(time库)

相关代码展示

import time
 
def is_star(x, y):
    c1 = (x**2 + y**2 - 1) ** 3 <= 3.6 * x ** 2 * y ** 3
    c2 = (-2.4 < x < -2.1 and -1 <= y <= 1.5)
    c3 = ((2.2 < x < 2.5 or 3.4 < x < 3.7) and -1 <= y <= 1.5)
    c4 = (-1 <= y < -0.6 and 2.2 < x < 3.7)
 
    return c1 or c2 or c3 or c4
 
y = 2.5
while y>=-1.6:
    x = -3.0
    while x<=4.0:
        print('*' if is_star(x, y) else ' ', end="")
        x += 0.1
    print()
    time.sleep(0.2)
    y -= 0.25

2.渐变爱心(numpy库)(matplotlib库)

相关代码展示

import numpy as np
import matplotlib.pyplot as plt
 
x_coords = np.linspace(-100, 100, 500)
y_coords = np.linspace(-100, 100, 500)
points = []
for y in y_coords:
    for x in x_coords:
        if ((x*0.03)**2+(y*0.03)**2-1)**3-(x*0.03)**2*(y*0.03)**3 <= 0:
            points.append({"x": x, "y": y})
heart_x = list(map(lambda point: point["x"], points))
heart_y = list(map(lambda point: point["y"], points))
 
plt.scatter(heart_x, heart_y, s=10, alpha=0.5, c=range(len(heart_x)), cmap="spring")
plt.show()

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值