用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
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有