Python 画实心月牙
Python 是一种非常流行的编程语言,具有各种各样的利用。其中,Python 也能够用来画图。本文将介绍怎么用 Python 画一个实心的月牙图案。
import turtle turtle.speed(0) # 画月牙图案的上半部份 turtle.begin_fill() turtle.color("gray") turtle.penup() turtle.goto(0, 80) turtle.pendown() turtle.circle(80, 180) turtle.end_fill() # 画月牙图案的下半部份 turtle.begin_fill() turtle.color("white") turtle.circle(80, 180) turtle.end_fill() # 隐藏海龟画笔 turtle.hideturtle() turtle.done()
以上代码使用 turtle 模块来画图。首先,通过设置 turtle 的速度为 0,可让程序运行得更快。然后,用 turtle.begin_fill() 开始填充色彩,用 turtle.end_fill() 结束填充色彩。通过 turtle.color() 来设置色彩,"gray" 和 "white" 分别用来填充上半部份和下半部份。turtle.penup() 和 turtle.pendown() 可让海龟画笔抬起或放下。turtle.goto() 可让海龟移动到指定的位置,而 turtle.circle() 可以画圆。最后,由于不需要看到海龟画笔的移动痕迹,使用 turtle.hideturtle() 隐藏海龟画笔。
文章来源:丸子建站
文章标题:Python 画实心月牙
https://www.wanzijz.com/view/58180.html