Here are resources about Turtle and TK symbolic colors name:
Altering the Turtle
Altering the Turtle. So far, the turtle has been in its default state, but nearly every aspect of its appearance can be changed. In this section, you’ll see how to do this, starting off by taking a look at color. Before we look at the code, a quick explanation of the three ways you can specify colors in
turtle is in order. The first is a named color, such as
"blue", seen here.
The full list of the Tk graphic toolkit colors is linked at the bottom of this slide and has over 700 named colors in there, so you may find this useful if you have favorites that you want to use often. The second is using a hex code, commonly used in websites. Here, each channel of red, green, and blue is specified as a two-digit hexadecimal number ranging from
FF. Don’t worry about using this if you don’t understand how hex codes work, but if you have a favorite color from a web page, you may be able to use it with this method.
The third method is specifying a tuple of color intensities from
1.0. Again, each one of these represents a color channel—red, green, and blue—but it’s easier to understand than the hex code seen above as the intensities range from
It’s also easier to program variables to have these values, allowing variation in the colors onscreen to be controlled by the code you write. Let’s take a look at those three systems in action across a few different
turtle commands. First up, the
02:13 It’s also possible to change the background color, but this is a function of the screen and not the turtle. Here, instead of using a named color, we’re going to use three numbers as seen in the previous slides.
You just need to tell it when you’re starting, what you want to be filled in with
.begin_fill(), and then when to do the filling in with
.end_fill(). So here, the fill is begun and now the shape is drawn.
Changing the pen speed. By default, the turtle draws at a leisurely pace, allowing its movement to be followed as your code runs. There may be times when this default is too fast or too slow, and this can be altered with the
.speed() function, providing the turtle with a speed, either a number from
10 or a string chosen from
As you can see, the
turtle has changed, and if we rotate it and move forward, you can see the line has also changed as has the speed. Once you have an idea of how you want to customize your turtle, this can often be the way to go.
Become a Member to join the conversation.