首页 > 编程语言 >python画爱心

python画爱心

时间:2022-10-17 12:46:18浏览次数:46  
标签:goto python align colors 爱心 red font def

import py2exe
import time
 
from distutils.core import setup

from turtle import *
 
# setup(
#     # console和windows分别代表控制台和图形界面,按需求选择
#     console = [{"script" : 'comtrade.py'}],
#     windows = [{"script":"comtrade.py", "icon_resources": [(1, "logo.ico")]} ],
#     name = 'comtrade', # 生成的exe文件名
#     version = '1.0',
#     options={}, # 括号内填入的为项目所需的依赖库和会造成报错的文件
#     data_files={})# 括号内输入的为项目所需的依赖文件
# version ,description,name不是必须要写的。
 
def setTurtle():
    # 窗口大小
    screensize(900, 700, 'pink')
    # 颜色
    color('red', 'pink')
    # 笔粗细
    pensize(3)
    # 速度
    speed(6)
    # 提笔
    penup()
 
 
def getStart(h):
    # 去到的坐标,窗口中心为0,0
    goto(0, -180)
    r = h / 5
    drawBigL(r, h)
    drawBigArc(r, 140)
    drawBigArc(r, 70)
    drawBigR(r, h)
    centerRange()
    drawHope()
    drawName()
 
 
def drawBigL(r, h):
    colors = ['red', 'orange', 'yellow', '#87CEEB', 'violet', 'red']
    for i in range(int(240 / h) + 1):
        seth(0)
        color(colors[i], colors[i + 1])
        drawHeart(r)
        seth(140)
        fd(h)
 
 
def drawBigArc(r, rad):
    colors = ['red', 'orange', 'yellow', 'SkyBlue', 'violet', 'red']
    for i in range(50):
        if i % 10 == 0:
            color(colors[int(i / 10)], colors[int(i / 10) + 1])
            seth(0)
            drawHeart(r)
            seth(rad - (i + 1) * 4)
        rt(4)
        fd(10.5)
 
 
def drawBigR(r, h):
    colors = ['red', 'orange', 'yellow', 'SkyBlue', 'violet', 'red']
    for i in range(int(240 / h) + 1):
        color(colors[i], colors[i + 1])
        seth(0)
        drawHeart(r)
        setheading(220)
        fd(h)
 
 
def drawHeart(r):
    down()
    begin_fill()
    factor = 180
    seth(45)
    circle(-r, factor)
    fd(2 * r)
    right(90)
    fd(2 * r)
    circle(-r, factor)
    end_fill()
    up()
 
 
# 在心中写字
def centerRange():
    for i in range(6):
        drawCenter(i)
        time.sleep(1)
 
 
def drawCenter(i):
    goto(0, 0)
    colors = ['red', 'orange', 'yellow', 'SkyBlue', 'violet', 'red']
    pencolor(colors[i])
    # 在心中写字 font可以设置字体自己电脑有的都可以设 align开始写字的位置
    # write('love ...', font=('gungsuh', 30,), align="center")
    up()
 
 

# 写寄语
def drawHope():
    pencolor('black')
    goto(5, 100)
    showturtle()
    write('xxx跨年快乐!', font=('华文行楷', 25,), align="center", move=True)
    goto(0, 50)
    write('余生有你一切都好', font=('华文行楷', 25,), align="center", move=True)
 
 
# 写署名
def drawName():
    pencolor('black')
    goto(0, 0)
    showturtle()
    write('相信下一年可以会更好', font=('华文行楷', 25,), align="center", move=True)
    goto(0, -50)
    write('来自xx的祝贺', font=('华文行楷', 25,), align="center", move=True)
 
 
setTurtle()
getStart(80)
 
# 点击窗口关闭
window = Screen()
window.exitonclick()

 

标签:goto,python,align,colors,爱心,red,font,def
From: https://www.cnblogs.com/xwsfw/p/16798808.html

相关文章