简体   繁体   中英

Python Turtle colour shades

I have some simple code to draw some squares. What I want to do is to fill each square with a progressively darker shade of grey (so first square is filled in white, the next one slightly darker grey, and so forth). How can I do this, within the code below? Any help would be much appreciated. Thank you. Brandon

import turtle

for count in range(15):

turtle.color("black", "grey45")

turtle.begin_fill()

turtle.left(20)

turtle.forward(100)

turtle.left(90)

turtle.forward(100)

turtle.left(90)

turtle.forward(100)

turtle.left(90)

turtle.forward(100)

turtle.left(90)

turtle.end_fill()
import turtle

turtle.color("black", "white")

turtle.colormode(1.0)

SQUARES = 18

SIDE = 100

shade = 1.0

for count in range(SQUARES):

    turtle.fillcolor(shade, shade, shade)

    turtle.begin_fill()

    turtle.left(360 // SQUARES)

    for side in range(4):

        turtle.forward(SIDE)

        turtle.left(90)

    turtle.end_fill()

    shade -= turtle.colormode() / float(SQUARES)

turtle.done()

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM