实例代码

#coding=utf-8
'''
采用随机颜色,以等差数列为半径,绘制同心圆
'''
import turtle as turtle
import random as random

turtle.screensize(600, 600, "white")
turtle.speed(0)      # turtle的运动速度设置为最快
turtle.hideturtle()  # 隐藏turtle

def getRandomColor():
    '''
    产生随机颜色
    :return:
    '''
    r = random.randint(16, 255)
    g = random.randint(16, 255)
    b = random.randint(16, 255)
    return "#" + str(hex(r)).replace("0x", "") + str(hex(g)).replace("0x", "") + str(hex(b)).replace("0x", "")


def drawCircle():
    '''
    绘制同心圆环
    :return:
    '''
    step = 12    # 圆环半径增长的步长
    for i in range(1, 256, step):

        color = getRandomColor()   # 获得随机颜色
        turtle.goto(0, -i)   # 注意移动起笔位置
        turtle.color(color,color)   # 设置颜色
        turtle.pensize(step * 1.5)   # 为了不留下空白,将线宽设置为1.5倍步长
        turtle.pendown()   # 落笔
        turtle.circle(i, 360)     # 绘制圆弧
        turtle.penup()     # 抬笔

if __name__ == "__main__":
    drawCircle()
    turtle.done()

运行结果

python画同心圆定义圆心 python怎么画同心圆_python画同心圆定义圆心