python タートルで雪だるまを描く方法は?
以下のPythonのタートルモジュールを使用した雪だるまの描画の例です。
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()
上記のコードを実行すると、キャンバスに可愛らしい雪だるまが描画されます。各部分のスタイルは、お好みで変更できます。