Python是一種廣泛應(yīng)用于數(shù)據(jù)分析、科學(xué)計(jì)算和機(jī)器學(xué)習(xí)的編程語言,也可以用來進(jìn)行圖形繪制。下面我們來嘗試用Python繪制一幅小狐貍吧!
# 導(dǎo)入必要的繪圖庫 import turtle # 設(shè)置畫布大小 turtle.setup(width=600, height=600) # 定義畫筆 pen = turtle.Pen() # 繪制狐貍的臉 pen.penup() pen.goto(-100, 180) pen.pendown() pen.fillcolor("#FFC0CB") pen.begin_fill() pen.circle(80) pen.end_fill() # 繪制狐貍的耳朵 pen.penup() pen.goto(-100, 220) pen.pendown() pen.fillcolor("#FFC0CB") pen.begin_fill() pen.right(45) pen.forward(30) pen.right(100) pen.forward(30) pen.right(135) pen.forward(45) pen.end_fill() pen.penup() pen.goto(20, 220) pen.pendown() pen.fillcolor("#FFC0CB") pen.begin_fill() pen.left(45) pen.forward(30) pen.left(100) pen.forward(30) pen.left(135) pen.forward(45) pen.end_fill() # 繪制狐貍的眼睛 pen.penup() pen.goto(-50, 240) pen.pendown() pen.fillcolor("#FFFFFF") pen.begin_fill() pen.circle(18) pen.end_fill() pen.penup() pen.goto(-50, 240) pen.pendown() pen.fillcolor("#000000") pen.begin_fill() pen.circle(10) pen.end_fill() pen.penup() pen.goto(20, 240) pen.pendown() pen.fillcolor("#FFFFFF") pen.begin_fill() pen.circle(18) pen.end_fill() pen.penup() pen.goto(20, 240) pen.pendown() pen.fillcolor("#000000") pen.begin_fill() pen.circle(10) pen.end_fill() # 繪制狐貍的嘴巴 pen.penup() pen.goto(-40, 200) pen.pendown() pen.right(60) pen.forward(40) pen.left(120) pen.forward(40) # 繪制狐貍的身體 pen.penup() pen.goto(-120, 80) pen.pendown() pen.fillcolor("#FFC0CB") pen.begin_fill() pen.right(30) pen.forward(120) pen.right(140) pen.forward(100) pen.right(140) pen.forward(120) pen.right(40) pen.forward(50) pen.end_fill() # 繪制狐貍的尾巴 pen.penup() pen.goto(-110, 50) pen.pendown() pen.fillcolor("#FFC0CB") pen.begin_fill() pen.right(30) pen.forward(50) pen.right(120) pen.forward(80) pen.right(120) pen.forward(80) pen.end_fill() # 隱藏畫筆 pen.hideturtle() # 顯示繪制結(jié)果 turtle.done()
運(yùn)行以上代碼,即可看到一個(gè)可愛的小狐貍呈現(xiàn)在屏幕上了!