import turtle as t
def draw_turtle():
# 设置屏幕
screen = t.Screen()
screen.title("用Python画一只乌龟")
screen.bgcolor("lightblue") # 背景色
# 创建画笔
pen = t.Turtle()
pen.speed(3) # 画图速度 (1-10, 0为最快)
pen.width(3) # 线条宽度
pen.hideturtle() # 隐藏默认的箭头形状,我们自己画
# --- 1. 画龟壳 (身体) ---
pen.penup()
pen.goto(0, -50)
pen.pendown()
pen.color("black", "green") # 轮廓黑,填充绿
pen.begin_fill()
pen.circle(50) # 画一个圆作为壳
pen.end_fill()
# 画壳上的花纹 (简单的六边形网格示意)
pen.penup()
pen.goto(0, -10)
pen.pendown()
pen.color("darkgreen")
pen.width(2)
for i in range(6):
pen.right(60)
pen.forward(30)
pen.backward(30)
# --- 2. 画头 ---
pen.penup()
pen.goto(40, 10) # 头的位置
pen.setheading(0)
pen.pendown()
pen.color("black", "lightgreen")
pen.begin_fill()
pen.circle(20)
pen.end_fill()
# 画眼睛
pen.penup()
pen.goto(55, 35)
pen.pendown()
pen.color("black")
pen.dot(5) # 画一个实心圆点作为眼睛
# --- 3. 画四肢 ---
limbs_positions = [
(-30, -20, 220), # 左后
(-30, 20, 140), # 左前
(30, -20, -40), # 右后
(30, 20, 40) # 右前
]
pen.color("black", "lightgreen")
for x, y, heading in limbs_positions:
pen.penup()
pen.goto(x, y)
pen.setheading(heading)
pen.pendown()
pen.begin_fill()
# 画椭圆形的脚
pen.circle(15, 180)
pen.end_fill()
# --- 4. 画尾巴 ---
pen.penup()
pen.goto(-50, -10)
pen.setheading(180)
pen.pendown()
pen.color("black", "lightgreen")
pen.begin_fill()
pen.right(30)
pen.forward(20)
pen.right(120)
pen.forward(20)
pen.end_fill()
# 完成
pen.penup()
pen.goto(0, -100)
pen.color("black")
pen.write("这是一只Python乌龟!", align="center", font=("Arial", 16, "bold"))
# 点击关闭
screen.exitonclick()
if __name__ == "__main__":
draw_turtle()
世界,您好!
欢迎使用 WordPress。这是您的第一篇文章。编辑或删除它,然后开始写作吧!