Python turtle 玩出花儿

用Python turtle经过简单的重复与规律就可以作出很多美感十足的画面。下面的代码是个模版。只需要调整相应的参数,用好随机数就可以玩出花样来!
下图就是用同一代码模版生成的(代码见文末)。


代码绘图案例1
代码绘图案例2
from turtle import *
from random import *
Screen().bgcolor("yellow")
colormode(255)#设置颜色模式
speed(0)
#画方块函数drawRect参数依次为 坐标x、坐标y、边长、颜色、旋转角度
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):
    #下面三行设置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)

调整参数,也可以变为下面的样子。


代码绘图案例3
代码绘图案例4
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容