用Python turtle經(jīng)過簡單的重復(fù)與規(guī)律就可以作出很多美感十足的畫面。下面的代碼是個模版。只需要調(diào)整相應(yīng)的參數(shù),用好隨機數(shù)就可以玩出花樣來!
下圖就是用同一代碼模版生成的(代碼見文末)。

代碼繪圖案例1

代碼繪圖案例2
from turtle import *
from random import *
Screen().bgcolor("yellow")
colormode(255)#設(shè)置顏色模式
speed(0)
#畫方塊函數(shù)drawRect參數(shù)依次為 坐標x、坐標y、邊長、顏色、旋轉(zhuǎn)角度
def drawRect(x,y,l,col,angle):
penup()
goto(x,y)
fillcolor(col)
begin_fill()
right(angle)
circle(l,360,4)
end_fill()
left(angle)
pendown()
for i in range(36):
#下面三行設(shè)置RGB顏色
r=0
g=randint(160,255)
b=randint(160,255)
color1=(r,g,b)
drawRect(0,0,120,color1,i*10)
for i in range(36):
r=0
g=randint(160,255)
b=randint(160,255)
color1=(r,g,b)
drawRect(0,0,120-i*3,color1,i*10)
調(diào)整參數(shù),也可以變?yōu)橄旅娴臉幼印?/p>

代碼繪圖案例3

代碼繪圖案例4