
import random
from math import sin, cos, pi, log
from tkinter import Tk, Canvas# 画布参数
CANVAS_WIDTH = 640
CANVAS_HEIGHT = 480
CANVAS_CENTER_X = CANVAS_WIDTH / 2
CANVAS_CENTER_Y = CANVAS_HEIGHT / 2
IMAGE_ENLARGE = 11
HEART_COLOR = "#ff2121"def heart_function(t, shrink_ratio: float = IMAGE_ENLARGE):"""生成心形曲线上的点坐标"""x = 16 * (sin(t) ** 3)y = -(13 * cos(t) - 5 * cos(2 * t) - 2 * cos(3 * t) - cos(4 * t)) # 修复不完整的行x *= shrink_ratioy *= shrink_ratiox += CANVAS_CENTER_Xy += CANVAS_CENTER_Yreturn int(x), int(y)def scatter_inside(x, y, beta=0.15):"""在心形内部随机扩散点"""ratio_x = -beta * log(random.random())ratio_y = -beta * log(random.random())dx = ratio_x * (x - CANVAS_CENTER_X)