Python turtle绘制多彩同心圆

使用python绘制随机颜色的同心圆
用turtle函数画空心圆
turtle.circle是从下方开始画圆的,所以要画同心圆的话,每一次都要将画笔移动到下一个圆的底部位置。

画笔的坐标默认在0,0,就以它为圆心。
因为turtle画圆的时候是从圆的底部开始画的,所以需要找到四个圆底部的坐标

随机颜色呢
首先要设置turtle库的颜色模式为RGB模式
然后通过random库去随机颜色

代码如下:

import turtle as t
import random

t.colormode(255)
t.speed(0)

for i in range(1, 10):
    t.pu()
    t.goto(0, -i * 10)
    t.pd()
    t.color(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))
    t.circle(i * 10)
t.done()

效果如下:
image.png

Python问题解答私信我

猜你喜欢

转载自blog.csdn.net/Miku_wx/article/details/111792575