随笔 - 633,  文章 - 0,  评论 - 13,  阅读 - 48万
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import turtle
import random
import math
 
# 初始化
turtle.setup(1280, 720)
t = turtle.Pen()
t.ht()
 
# 颜色
colors = []
t_list = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"]
 
for i in t_list:
    t_str = "#ff00"
    for j in t_list:
        colors.append(t_str+i+j)
 
 
class Love():
    def __init__(self):
        # 定义变量
        self.r = random.randint(4, 10)
        self.x = random.randint(-900, 700)
        self.y = random.randint(-400, 400)
        self.i = random.randint(0, 10)
        self.color = random.choice(colors)
        self.speed = random.randint(1, 8)
 
    def move(self):
        # 通过y坐标来控制爱心
        if self.y <= 500:
            self.y += 2.5*self.speed
            self.x = self.x + 1.5*math.sin(self.i)*math.sqrt(self.i)*self.speed
            self.i = self.i + 0.1
        else:
            self.y = -700
            self.r = random.randint(5, 20)
            self.x = random.randint(-900, 700)
            self.i = 0
            self.color = random.choice(colors)
            self.speed = random.randint(1, 8)
 
    def draw(self):
        # 绘制爱心
        t.pensize(self.r/2)
        t.penup()
        t.color(self.color, self.color)
        t.goto(self.x, self.y)
        t.pendown()
        # 设置角度
        t.setheading(60)
        t.circle(self.r, 255)
        t.fd(2.4*self.r)
        t.left(90)
        t.fd(2.4*self.r)
        t.circle(self.r, 255)
 
 
love = []
for i in range(100):
    love.append(Love())
turtle.bgcolor("#000000")
 
 
while 1:
    turtle.tracer(0)
    t.clear()
    for i in range(80):
        love[i].move()
        love[i].draw()
    turtle.tracer(1)

  

posted on   大话人生  阅读(51)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
点击右上角即可分享
微信分享提示