以下是一個利用Python畫出冰墩墩的完整源代碼:
import turtle
# 設置畫布大小和背景顏色
turtle.setup(800, 600)
turtle.bgcolor("#0077be")
# 設置畫筆屬性
turtle.penup()
turtle.speed(10)
turtle.hideturtle()
# 畫出冰墩墩的身體
turtle.goto(-100, 0)
turtle.pendown()
turtle.fillcolor("#ffffff")
turtle.begin_fill()
turtle.circle(100)
turtle.end_fill()
# 畫出冰墩墩的臉部
turtle.penup()
turtle.goto(-50, 50)
turtle.pendown()
turtle.fillcolor("#000000")
turtle.begin_fill()
turtle.circle(15)
turtle.end_fill()
# 畫出冰墩墩的眼睛
turtle.penup()
turtle.goto(-60, 60)
turtle.pendown()
turtle.fillcolor("#ffffff")
turtle.begin_fill()
turtle.circle(5)
turtle.end_fill()
turtle.penup()
turtle.goto(-40, 60)
turtle.pendown()
turtle.fillcolor("#ffffff")
turtle.begin_fill()
turtle.circle(5)
turtle.end_fill()
# 畫出冰墩墩的嘴巴
turtle.penup()
turtle.goto(-70, 40)
turtle.pendown()
turtle.pensize(3)
turtle.right(90)
turtle.circle(70, 180)
# 畫出冰墩墩的帽子
turtle.penup()
turtle.goto(-100, 100)
turtle.pendown()
turtle.fillcolor("#ff0000")
turtle.begin_fill()
turtle.forward(200)
turtle.right(90)
turtle.forward(30)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(30)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(30)
turtle.right(90)
turtle.forward(70)
turtle.right(90)
turtle.end_fill()
# 畫出冰墩墩的圍巾
turtle.penup()
turtle.goto(-100, -70)
turtle.pendown()
turtle.pensize(10)
turtle.pencolor("#ff0000")
turtle.right(45)
turtle.forward(100)
turtle.left(90)
turtle.forward(50)
turtle.left(90)
turtle.forward(100)
turtle.left(90)
turtle.forward(50)
turtle.left(135)
turtle.done()
運行該代碼,即可在turtle圖形窗口中看到畫出的冰墩墩形狀。