本文主要是介绍Python绘制爱心,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
import turtle# 设置画布和画笔
canvas = turtle.Screen()
canvas.bgcolor("black")
pen = turtle.Turtle()
pen.color("red")
pen.shape("turtle")
pen.speed(2)# 绘制爱心
pen.up()
pen.goto(0, -100)
pen.down()
pen.begin_fill()
pen.left(140)
pen.forward(224)
for i in range(200):pen.right(1)pen.forward(2)
pen.left(120)
for i in range(200):pen.right(1)pen.forward(2)
pen.forward(224)
pen.end_fill()# 隐藏画笔
pen.hideturtle()# 结束绘制
turtle.done()
这篇关于Python绘制爱心的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!