如何在python中画方中圆并涂上不同颜色?

Python022

如何在python中画方中圆并涂上不同颜色?,第1张

import math

import turtle

turtle.seth(0)

turtle.penup()

turtle.goto(-200 / math.sqrt(2),-200 / math.sqrt(2))#方形的边长÷2

turtle.right(45)

turtle.color("red")#方形的颜色

turtle.pendown()

turtle.begin_fill()

turtle.circle(200,steps=4)#方形的对角线长度÷2

turtle.end_fill()

turtle.penup()

turtle.color("yellow")#圆形的颜色

turtle.home()

turtle.goto(0,-100)#圆形的半径

turtle.begin_fill()

turtle.circle(100)#圆形的半径

turtle.end_fill()

from turtle import *

colors = ['red', 'blue', 'green', 'yellow', 'orange', 'purple']

def circle():

    for i in range(36):

        forward(20)

        left(10)

for i in colors:

    color(i)

    begin_fill()

    circle()

    end_fill()

    left(60)