动态爱心代码-python

浅蹭了一波热度,搞了个简易版本,代码如下:

import numpy as np
import math
from tkinter import *
import random

pi = math.pi

width = 680
height = 680
center_x = width/2
center_y = height/2
color = "#990000"
c2 = '#990000'

#x = 16sint^3
#y = 13cost - 5cos2t - 2cos3t -cos4t
def heart_function(t):
    # t = np.linspace(0,2*pi)
    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)

    return x,y
#在一定范围内随机抖动
def scatter(x,y,ratio):
    while(1):
        rand = random.random()
        if(rand!=0):
            break
    x =  - ratio*math.log10(rand)
    y =  - ratio*math.log2(rand)
    return x,y


#画图

def Graph(x_s,y_s,x0,y0,c=color,shrink_size=11):
    w1,w2 = shrink_size,shrink_size-1 #缩放倍数
    # 内部填充
    add_scatters(x_s, y_s, x0, y0,shrink_size=w2)
    #填充外部
    for j in range(len(x_s)):
        ratio1 = m

你可能感兴趣的:(python,开发语言)