Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3648231
  • 博文数量: 365
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 2522
  • 用 户 组: 普通用户
  • 注册时间: 2019-10-28 13:40
文章分类

全部博文(365)

文章存档

2023年(8)

2022年(130)

2021年(155)

2020年(50)

2019年(22)

我的朋友

分类: Python/Ruby

2022-09-02 12:02:21

# @Time : 2022/8/23 10:38

# @Author : Dream

# @File : 中秋节.py

import turtle

import time

import pygame

import random

import tkinter as tk

import threading

def drawMoon():  # 绘制月亮

    turtle.penup()  # 画笔拿起

    turtle.goto(-150, 0)

    turtle.fillcolor('yellow')  # 圆月的颜色

    turtle.pendown()  # 画笔放下

    turtle.begin_fill()

    turtle.circle(112)

    turtle.end_fill()  # turtle.begin_fill() turtle.end_fill() 颜色填充

def drawCloud():  # 绘制云朵

    turtle.penup()

    turtle.goto(-500, 200)

    turtle.fillcolor((245, 245, 245))

    turtle.pencolor((255, 255, 255))

    turtle.pensize(5)

    turtle.pendown()

    turtle.forward(250)

    def cloud(mode='right'):

        for i in range(90):

            turtle.pensize((i + 1) * 0.2 + 5)

            turtle.right(1) if mode == 'right' else turtle.left(1)

            turtle.forward(0.5)

        for i in range(90):

            turtle.pensize(90 * 0.2 + 5 - 0.2 * (i + 1))

            turtle.right(1) if mode == 'right' else turtle.left(1)

            turtle.forward(0.5)

    cloud()

    turtle.forward(100)

    cloud('left')

    turtle.forward(600)

def drawMountain():  # 绘制山川

    turtle.penup()

    turtle.goto(-500, -250)

    turtle.pensize(4)

    turtle.fillcolor((36, 36, 36))

    turtle.pencolor((31, 28, 24))

    turtle.pendown()

    turtle.begin_fill()

    turtle.left(20)

    turtle.forward(400)

    turtle.right(45)

    turtle.forward(200)

    turtle.left(60)

    turtle.forward(300)

    turtle.right(70)

    turtle.forward(300)

    turtle.goto(500, -300)

    turtle.goto(-500, -300)

    turtle.end_fill()

def initTurtle():

    pygame.mixer.init()

    pygame.mixer.music.load('寂寞烟火.mp3')

    pygame.mixer.music.play(-1, 20.0)

    turtle.hideturtle()

    turtle.setup(1000, 600)

    turtle.title('中秋祝福')

    turtle.colormode(255)

    turtle.bgcolor('blue')

    turtle.speed(1)

def writezhufu():

    turtle.penup()

    turtle.goto(400, -150)

    turtle.pencolor((250, 240, 230))

    # 诗句

    potery = ['\n\n\n\n\n\n','\n\n\n\n\n\n']

    # 诗句位置(可自行设计添加), 最好2/4句五言诗

    coordinates =跟单网gendan5.com [(300, -150), (200, -150), (100, -150)]

    for i, p in enumerate(potery):

        turtle.write(p, align="center", font=("STXingkai", 50, "bold"))

        if (i + 1) != len(potery):

            time.sleep(2)

            turtle.goto(coordinates[i])

    # 祝福话语

    turtle.penup()

    turtle.hideturtle()    #隐藏箭头显示

    turtle.goto(-110, -100)

    turtle.color('red')

    turtle.write('宝贝,中秋节快乐!', align="center", font=("STXingkai", 50, "bold"))

# 弹窗设置

def dow():

    window = tk.Tk()

    width = window.winfo_screenwidth()

    height = window.winfo_screenheight()

    a = random.randrange(0, width)

    b = random.randrange(0, height)

    window.title('中秋快乐')

    window.geometry("200x50" + "+" + str(a) + "+" + str(b))

    tk.Label(window,

             text='亲爱的中秋快乐',  # 标签的文字

             bg='red',  # 背景颜色

             font=('..', 17),  # 字体和字体大小

             width=18, height=2  # 标签长宽

             ).pack()  # 固定窗口位置

    window.mainloop()

def main():

    initTurtle()

    drawMoon()  # 绘制月亮

    drawCloud()  # 绘制云朵

    drawMountain()  # 绘制山

    writezhufu()  # 写诗

    time.sleep(2)

    threads = []

    for i in range(100):  # 需要的弹框数量

        t = threading.Thread(target=dow)

        threads.append(t)

        time.sleep(0.01)

        threads[i].start()

if __name__ == '__main__':

    main()

阅读(464) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~