下面是一個使用Python Turtle模塊繪制雪人的示例代碼:
import turtle
# 設置畫布
turtle.setup(800, 600)
turtle.bgcolor("skyblue")
turtle.title("Snowman")
# 繪制雪人身體
turtle.penup()
turtle.goto(-100, -100)
turtle.pendown()
turtle.begin_fill()
turtle.circle(40)
turtle.end_fill()
# 繪制雪人頭部
turtle.penup()
turtle.goto(-100, 0)
turtle.pendown()
turtle.begin_fill()
turtle.circle(30)
turtle.end_fill()
# 繪制雪人眼睛
turtle.penup()
turtle.goto(-115, 10)
turtle.pendown()
turtle.begin_fill()
turtle.circle(3)
turtle.end_fill()
turtle.penup()
turtle.goto(-85, 10)
turtle.pendown()
turtle.begin_fill()
turtle.circle(3)
turtle.end_fill()
# 繪制雪人鼻子
turtle.penup()
turtle.goto(-100, -10)
turtle.pendown()
turtle.pensize(3)
turtle.pencolor("orange")
turtle.setheading(60)
turtle.circle(10, 120)
turtle.setheading(180)
turtle.circle(10, 120)
turtle.setheading(0)
turtle.circle(10, 120)
# 繪制雪人帽子
turtle.penup()
turtle.goto(-135, 50)
turtle.pendown()
turtle.begin_fill()
turtle.color("red")
turtle.forward(70)
turtle.left(90)
turtle.forward(30)
turtle.left(90)
turtle.forward(70)
turtle.left(90)
turtle.forward(30)
turtle.end_fill()
# 繪制雪人圍巾
turtle.penup()
turtle.goto(-100, -20)
turtle.pendown()
turtle.pensize(5)
turtle.pencolor("green")
turtle.setheading(-90)
turtle.forward(50)
turtle.right(90)
turtle.forward(30)
turtle.right(90)
turtle.forward(60)
turtle.hideturtle()
turtle.done()
運行上述代碼后,將會在畫布上繪制出一個可愛的雪人。你可以根據自己的喜好進行各部分的樣式修改。