Python語(yǔ)言在人工智能、數(shù)據(jù)分析等領(lǐng)域有廣泛應(yīng)用,同時(shí)還能通過(guò)一些第三方庫(kù)進(jìn)行創(chuàng)意編程,例如用Python畫(huà)小雞6。
import turtle # 設(shè)置畫(huà)布大小 turtle.setup(800, 600) # 將海龜移至小雞的頭部位置,并面向東方 turtle.penup() turtle.goto(-150,0) turtle.pensize(5) turtle.pencolor('orange') turtle.pd() # 畫(huà)頭部 turtle.begin_fill() turtle.setheading(60) # 小雞頭的30度角度 turtle.circle(-100, 60) turtle.circle(-10, 180) turtle.circle(-100, 60) turtle.end_fill() turtle.pu() turtle.goto(-80,37) turtle.pd() turtle.fillcolor('white') # 畫(huà)眼睛 turtle.begin_fill() turtle.circle(45) turtle.end_fill() turtle.pu() turtle.goto(-75,70) turtle.pd() turtle.fillcolor('black') turtule.begin_fill() turtle.circle(20) turtle.end_fill() # 畫(huà)嘴巴 turtle.pu() turtle.goto(-10,-5) turtle.pd() turtle.setheading(270) turtle.circle(20,180) turtle.pu() turtle.goto(-5,-25) turtle.pd() turtle.forward(10) # 畫(huà)身體 turtle.pu() turtle.goto(60,-40) turtle.pd() turtle.fillcolor('orange') turtle.begin_fill() turtle.setheading(-50) turtle.circle(50, 240) turtle.setheading(0) turtle.forward(120) turtle.setheading(180) turtle.circle(-50, 240) turtle.setheading(180) turtle.forward(120) turtle.end_fill() # 畫(huà)翅膀 turtle.pu() turtle.goto(-70,-80) turtle.pd() turtle.fillcolor('white') turtle.begin_fill() turtle.setheading(50) turtle.circle(30, 240) turtle.setheading(0) turtle.forward(60) turtle.setheading(180) turtle.circle(-30, 240) turtle.setheading(180) turtle.forward(60) turtle.end_fill() # 畫(huà)腳 turtle.pu() turtle.goto(20, -150) turtle.pd() turtle.setheading(270) turtle.pensize(8) turtle.pencolor('orange') turtle.forward(70) turtle.pu() turtle.goto(75, -150) turtle.pd() turtle.forward(70) # 結(jié)束繪畫(huà) turtle.done()
運(yùn)行以上代碼,可以在畫(huà)布上看到一個(gè)可愛(ài)的小雞形狀。在這段代碼中,我們用turtle庫(kù)繪制出小雞的頭部、眼睛、嘴巴、身體、翅膀、腳等各個(gè)部分,同時(shí)調(diào)整海龜?shù)臓顟B(tài)和位置。
Python編程可以讓你發(fā)揮創(chuàng)意,畫(huà)出各種精美的圖形,同時(shí)提高編程技能和邏輯思維能力。如果你對(duì)這個(gè)領(lǐng)域感興趣,不妨開(kāi)始學(xué)習(xí)Python編程吧!