温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

python中的小人画爱心表白代码怎么写

发布时间:2021-09-26 10:13:30 来源:亿速云 阅读:376 作者:柒染 栏目:开发技术

本篇文章为大家展示了python中的小人画爱心表白代码怎么写,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。

导语

哈喽!我是木木子,又到了今日更新时刻!

python中的小人画爱心表白代码怎么写

我们来看看写什么呢?

小编有个好兄弟最近在追妹子,跟妹子打得火热!就差临门一脚了,这一jio我帮忙补上去了!

他问有没有什么酷炫的表白方式,可以给人心动的赶jio,表白的方式有许多种

今天木木子来教大家一个之前很火的小人画爱心表白代码!

python中的小人画爱心表白代码怎么写

正文

Turtle库是python的基础绘图库,这个库使用起来很方便,了解基础的一些信息之后学起来很快是小编绘图的首选!

首先绘制爱心

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(5)       # 画笔粗细
 
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()

效果如下:

python中的小人画爱心表白代码怎么写

其次绘制小人儿

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()

效果如下:

python中的小人画爱心表白代码怎么写

最后添加文字

 t.write("To: 你知道我的缺点是什么吗?", move=True, align="left", font=("楷体", 20, "normal"))

效果如下:

python中的小人画爱心表白代码怎么写

python中的小人画爱心表白代码怎么写

上述内容就是python中的小人画爱心表白代码怎么写,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注亿速云行业资讯频道。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI