利用Python如何画一颗心、小人发射爱心
作者:一个超会写Bug的安太狼 发布时间:2021-01-11 09:11:50
标签:python,小人,爱心
源码:
#!/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实现多线程的两种方式。分享给大家供大家参考,具体如下:目前python 提供了几种多线程实现方式 thread,t
- 解决静态资源失效的问题这就需要修改我们的 config 中的 index.js了,默认的build 中的部分是这样的: build: { &
- 许多人在数据科学、机器学习、web开发、脚本编写和自动化等领域中都会使用Python,它是一种十分流行的语言。Python流行的部分原因在于
- <script> Array.prototype.swap = function(i, j) { var temp = this
- 一、安装配置PHP1、下载Php的版本zip包之后,解压缩到指定目录。下载地址:http://www.php.net/downl
- 如果是报名培训班的话,学习的速度可能会更快一些,毕竟是自己花钱了。自学python爬虫方法:首先要掌握一些有关爬虫的基础知识,基本的要知道什
- 以前我在mysql中分页都是用的 limit 100000,20这样的方式,我相信你也是吧,但是要提高效率,让分页的代码效率更高一些,更快一
- 西贝做了许久的交互设计工作,每年的目标都有不同,却发现今年没有什么提高和改进的地方。也许是自己没有回头总结,总是被这样那样的借口推脱。最近休
- 有四个变量影响磁带备份设备的性能,并使 SQL Server 备份及还原性能操作得以在大体上随添加更多磁带设备而提高线性比例。◆软件数据块大
- 在开发中我们经常遇到这样的需求,需要用户直接点击一个链接进入到一个页面,用户点击后链接后会触发401拦截返回登录界面,登录后又跳转到链接的页
- TensorFlow保存模型代码import tensorflow as tffrom tensorflow.python.framewor
- 推荐的国内镜像站[ 个人推荐清华大学pypi镜像站(https://mirrors.tuna.tsinghua.edu.cn/help/py
- 这个游戏就是实现键盘上输入不同的数字,将圆分割成不同的几个部分,每部分用不同的颜色来实现。导入包导入随机包,pygame,系统包,time时
- 1.每个客户端连接都会从服务器进程中分到一个属于它的线程。而该连接的相应查询都都会通过该线程处理。2.服务器会缓存线程。因此并不会为每个新连
- 在 Django 网站中使用 mailgun 的邮件收发服务。1.在 mailgun 官网上注册个账号(免费,免费账号每个月有10000条收
- '$.browser.msie' 为空或不是对象,这个是jQuery错误出现这个错误,是因为升级了jQuery版本,从1.9
- 一 在写之前 最好指定python的路径:#!/usr/bin/pythonpython 在linux中需要添加编码方式:以免出现中文乱码#
- mysql优化是我们日常工作经常遇到的问题,今天给大家说下MySQL常见的几种优化方案。注:原始资料来自享学课堂,自己加上整理和思考思考sq
- 一、安装pip install apscheduler二、ApScheduler 简介1 APScheduler的组件triggers:触发
- 先给大家看下Scratch3.0二次开发之windows环境下打包成exe的流程。1、需要先安装npm,安装过程不作过多介绍了。