在Python中,我們可以使用turtle模塊來畫出簡易的圖形,包括動物。下面我們就來嘗試著用Python來畫一只海龜吧!
# 引入turtle模塊 import turtle # 創(chuàng)建一個(gè)畫布 turtle.setup(800, 600) # 創(chuàng)建一個(gè)畫筆 pen = turtle.Turtle() # 設(shè)置畫筆顏色、填充色和粗細(xì) pen.color("green", "yellow") pen.pensize(5) # 畫出海龜?shù)纳眢w pen.begin_fill() pen.circle(50) pen.end_fill() # 畫出海龜?shù)念^和四肢 pen.penup() pen.goto(50, 50) pen.pendown() pen.begin_fill() pen.goto(70, 70) pen.goto(90, 50) pen.goto(70, 30) pen.goto(50, 50) pen.end_fill() # 移動畫筆到海龜?shù)奈舶筒糠? pen.penup() pen.goto(-50, -50) pen.pendown() # 畫出海龜?shù)奈舶? pen.begin_fill() pen.goto(-70, -70) pen.goto(-90, -50) pen.goto(-70, -30) pen.goto(-50, -50) pen.end_fill() # 隱藏畫筆 pen.hideturtle() # 顯示畫布 turtle.done()
運(yùn)行上述代碼后,就可以在Python窗口中看到一只可愛的海龜了。