利用Python如何画一颗心、小人发射爱心
作者:一个超会写Bug的安太狼 时间:2021-01-11 09:11:50
源码:
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import turtle
import time
# 画心形圆弧
def hart_arc():
for i in range(200):
turtle.right(1)
turtle.forward(2)
def move_pen_position(x, y):
turtle.hideturtle() # 隐藏画笔(先)
turtle.up() # 提笔
turtle.goto(x, y) # 移动画笔到指定起始坐标(窗口中心为0,0)
turtle.down() # 下笔
turtle.showturtle() # 显示画笔
# 初始化
turtle.setup(width=800, height=500) # 窗口(画布)大小
turtle.color('red', 'pink') # 画笔颜色
turtle.pensize(3) # 画笔粗细
turtle.speed(1) # 描绘速度
# 初始化画笔起始坐标
move_pen_position(x=0,y=-180) # 移动画笔位置
turtle.left(140) # 向左旋转140度
turtle.begin_fill() # 标记背景填充位置
# 画心形直线( 左下方 )
turtle.forward(224) # 向前移动画笔,长度为224
# 画爱心圆弧
hart_arc() # 左侧圆弧
turtle.left(120) # 调整画笔角度
hart_arc() # 右侧圆弧
# 画心形直线( 右下方 )
turtle.forward(224)
turtle.end_fill() # 标记背景填充结束位置
# 点击窗口关闭程序
window = turtle.Screen()
window.exitonclick()
效果图:
源码:
import turtle as t
from time import sleep
def go_to(x, y):
t.up()
t.goto(x, y)
t.down()
def head(x, y, r):
go_to(x, y)
t.speed(20)
t.circle(r)
leg(x, y)
def leg(x, y):
t.right(90)
t.forward(180)
t.right(30)
t.forward(100)
t.left(120)
go_to(x, y - 180)
t.forward(100)
t.right(120)
t.forward(100)
t.left(120)
hand(x, y)
def hand(x, y):
go_to(x, y - 60)
t.forward(100)
t.left(60)
t.forward(100)
go_to(x, y - 90)
t.right(60)
t.forward(100)
t.right(60)
t.forward(100)
t.left(60)
eye(x, y)
def eye(x, y):
go_to(x - 50, y + 130)
t.right(90)
t.forward(50)
go_to(x + 40, y + 130)
t.forward(50)
t.left(90)
def big_Circle(size):
t.speed(20)
for i in range(150):
t.forward(size)
t.right(0.3)
def line(size):
t.speed(20)
t.forward(51 * size)
def small_Circle(size):
t.speed(20)
for i in range(210):
t.forward(size)
t.right(0.786)
def heart(x, y, size):
go_to(x, y)
t.left(150)
t.begin_fill()
line(size)
big_Circle(size)
small_Circle(size)
t.left(120)
small_Circle(size)
big_Circle(size)
line(size)
t.end_fill()
def main():
t.pensize(2)
t.color('red', 'pink')
head(-120, 100, 100)
heart(250, -80, 1)
go_to(100, -300)
t.write("To: 智慧与美貌并存的", move=True, align="left", font=("楷体", 20, "normal"))
t.done()
main()
效果图:
来源:https://blog.csdn.net/m0_46278037/article/details/113819989
标签:python,小人,爱心
0
投稿
猜你喜欢
你是真正的用户体验设计者吗? Ⅴ
2008-04-19 18:32:00
asp如何利用当前时间生成随机函数?
2010-01-01 15:44:00
基于Python创建可定制的HTTP服务器
2023-08-09 22:46:09
浅谈Python 命令行参数argparse写入图片路径操作
2023-03-18 21:08:11
Python面向对象实现方法总结
2022-03-11 08:50:41
Django中自定义查询对象的具体使用
2021-05-26 03:11:18
什么是XSLT,什么是XPath
2008-01-21 13:12:00
python线程信号量semaphore使用解析
2023-02-08 08:47:24
python WindowsError的错误代码详解
2021-09-03 18:58:45
pycharm配置pyqt5-tools开发环境的方法步骤
2022-01-05 08:31:00
从"..."看中国的UI设计界的粗糙
2007-11-21 19:28:00
PHP 二维数组根据某个字段排序的具体实现
2023-11-20 05:21:13
SQLServer WITH 的用法
2009-07-09 18:54:00
SQL 2005 sa islock用户不能正常登录的现象
2008-12-05 15:49:00
对于Python中线程问题的简单讲解
2023-12-28 10:16:31
Python 一句话生成字母表的方法
2022-03-15 06:49:47
Oracle 数据库操作类
2009-08-12 12:06:00
Python 数据类型--集合set
2021-11-23 21:17:54
Win 10下Anaconda虚拟环境的教程
2022-09-18 16:42:06
下拉列表两级连动的新方法(二)
2009-06-04 18:22:00