Python turtle color

In this tutorial, we will learn How to give color to the turtle in Python Turtle and we will also cover different examples related to Turtle color. And, we will cover these topics.

  • Python turtle color
  • Python turtle color RGB
  • Python turtle color chart
  • Python turtle color list
  • Python turtle color mode
  • Python turtle color fill
  • Python turtle color change
  • Python turtle color gradient

Python turtle color

The turtle is a module used for making graphics. We can draw different shapes, pictures with the help of a turtle here turtle are used as a pen with the help of the turtle we can draw anything and also fill color with the help of this turtle just giving the color to the shapes. We can give color to the turtle with the help of tur.color() function.

Code:

In the following code, we will use the turtle module from this turtle module we draw different shapes and pictures. The turtle() method is used to make objects.

  • turtl.title(“Pythontpoint“) is used to give the title to the window.
  • turtl.forward(120) is used to move the turtle in the forward direction.
  • turtl.right(90) is used to move the turtle in the right direction.
  • turtl.color(“blue”) is used to change the color of the turtle and the default color of the turtle is black.
from turtle import *

import turtle as turtl
 
turtl.title("Pythontpoint")

turtl.forward(120)
turtl.right(90)
 

turtl.color("blue")
 

turtl.forward(50)
turtl.done()

Output:

After running the code we get the following output in which we can see that the turtle is moving on the screen with its default color after taking the right turn its changes it’s color black to blue.

Python turtle color
Python turtle color

Python turtle color RGB

We can have different colors and we can choose any color and give any color to the turtle but in this, we can choose the most beautiful color red, green, blue(RGB). From these three-color, we can draw different shapes with the help of a turtle.

Code:

In the below code we import the turtle library for making shapes and pictures and here turtle is used as a pen. We can draw different shapes on the screen here screen is works as a drawing board.

  • turtl.title(“Pythontpoint”) is used to give a title to our window.
  • turtl.shape(“arrow”) is used to give an arrow shape to a turtle.
  • turtl.forward(150) is used to move the turtle in the forward direction.
  • turtl.pencolor(“red”) is used to give the red color to the pen.
  • turtl.right(90) is used to move the turtle in the right direction.
  • turtl.forward(150) is used to move the turtle in the forward direction.
from turtle import *
import turtle as turtl
turtl.title("Pythontpoint")

turtl.shape("arrow")

turtl.colormode(255)
turtl.forward(150)
 
turtl.pencolor("red")
 
turtl.right(90)
turtl.forward(150)
 
turtl.pencolor(("blue"))
 
turtl.right(90)
turtl.forward(150)
 
turtl.pencolor("green")
 
turtl.right(90)
turtl.forward(150)
turtl.done()

Output:

After running the above code we get the following output in which we can see that a square shape with RGB Color is drawn with the help of a turtle on the screen

Python turtle color RGB

Python turtle color chart

As we know we can draw different shapes with the help of a turtle we can also draw a bar chart with help of a turtle on the screen. This bar chart shows the position of the different tasks how much task is done by any people.

Code:

In the below code we will import the turtle module from which we can draw different charts on the screen and give different colors to the different charts.

  • turtl.title(“Pythontpoint”) is used to give the title to the window.
  • turtle.fillcolor(colr) is used to fill the color inside the shape.
  • turtle.begin_fill() is used to start filling the color after completing the shape.
  • turtle.left(90) is used to move the turtle in the left direction.
  • turtle.forward(heigh) is used to move the turtle in the forward direction.
  • turtle.right(90) is used to move the turtle in the right direction.
  • turtle.end_fill() is to stop filling the color.
from turtle import *
import turtle as turtl

def drawBar(turtle, heigh, colr):
   
    turtl.title("Pythontpoint")
    turtle.fillcolor(colr)
    turtle.begin_fill()             
    turtle.left(90)
    turtle.forward(heigh)
    turtle.write(str(heigh))
    turtle.right(90)
    turtle.forward(40)
    turtle.right(90)
    turtle.forward(heigh)
    turtle.left(90)
    turtle.end_fill()               
 
xaxis = [68, 137, 240, 106, 154, 280, 120]
colrs = ["light blue", "cyan", "red", "green",
        "yellow", "brown", "pink"]
 
maxheigh = max(xaxis)
number = len(xaxis)
brder = 10
 
win = turtl.Screen()            
win.setworldcoordinates(0 - brder, 0 - brder,
                       40 * number + brder,
                       maxheigh + brder)
  
tut = turtl.Turtle()          
tut.pensize(4)
  
for i in range(len(xaxis)):
     
    drawBar (tut, xaxis[i],
             colrs[i])
 
win.exitonclick()

Output:

After running the above code we get the this below output in which we can see that the bar chart is plotted on the screen.

Python turtle color chart
Python turtle color chart

Python turtle color list

As we know turtle is used to draw shapes and turtle is worked as open and we can draw different shapes, diagrams, and pictures with the help of a pen and we can change the color of the pen or draw a colorful shape on the screen and here screen works as a drawing board.

Code:

In the below code we create a list and in this list different colors are present and we can choose any color and give this color to the pen and draw a beautiful shape with them.

  • turtle.Turtle() The turtle() method is used to make shapes.
  • turtl.shape(‘triangle’) is used to give the triangle shape to the turtle.
  • turtl.begin_fill() is used to start filling the color.
  • turtl.color(colorList[8]) is used to choose the color from the list.
  • turtl.circle(20) is used to draw the shape of circle.
  • turtl.end_fill() is used to stop filling color.
from turtle import *
import turtle
import random
turtle.title("Pythontpoint")
turtl = turtle.Turtle()
turtl.shape('triangle')

colorList = ['yellow', 'cyan', 'red', 'light blue', 'pink',
  'blue', 'purple', 'green', 'brown', 'orange']

turtl.begin_fill()
turtl.color(colorList[8])
turtl.circle(20)
turtl.end_fill()
turtle.done()

Output:

After running the above code we get the following output in which we can see that a colored circle is drawn on the screen.

Python turtle color list
Python turtle color list

Python turtle color mode

Turtle is used to draw different shapes and also used to fill the color inside the shape from which our shape looks beautiful. The default color of the turtle is black and this default color is shown on the command prompt.

Code:

In the below code we will import the turtle module from which we draw the different shapes and give different colors to the shapes.

print(turtl.color()) is used to print the default color on the screen.

from turtle import *
import turtle as turtl
 
print(turtl.color())

Output:

After running the above output we get the following output in which we can see that the default color is printed on the command prompt.

Python turtle color mode
Python turtle color mode

Python turtle color fill

As we know the turtle is worked as a pen and we can draw different shapes with the help of the turtle and we can fill different color inside this shape with the help of the turtle and now this turtle work as a brush because it is filling the color inside the shape.

Code:

In the below code we can draw a square shape that is filled with beautiful colors and with this color our shape looks amazing.

  • turtl.Turtle() The turtle() method is used to make shapes.
  • turtle.fillcolor(color) is used to fill the color inside the shape.
  • turtle.begin_fill() is used to start filling color.
  • turtle.forward(side) is used to move the turtle in the forward direction.
  • turtle.right(150) is used to move the turtle in the right direction.
  • turtle.end_fill() is used tostop filling color.

from turtle import * 
import turtle as turtl
turtl.title("Pythontpoint")

turtle = turtl.Turtle()
  
side = 100
  

color = "blue"
  

turtle.fillcolor(color)
  

turtle.begin_fill()
  

for _ in range(4):
  turtle.forward(side)
  turtle.right(150)

turtle.end_fill()
turtl.done()

Output:

After running the above code we get the following output in which we can see that a beautiful shape with beautiful color is drawn on the screen.

Python turtle fill color
Python turtle fill color

Python turtle color change

The turtle can draw anything anywhere we can also give color to the turtle from which we can draw colored shapes. We can also change the color with the help of turtl.color() function.

Code:

In the following code, we will import the turtle module and with help of this turtle module we can draw the color the shape and we can also change the color with the help of this turtle.color().

  • turtl.forward(90) is used to move the turtle in the forward direction.
  • turtl.color(“purple”) is used to change the color of the turtle.
from turtle import *

import turtle as turtl
 
turtl.title("Pythontpoint")

turtl.forward(90)
 

turtl.color("purple")
 

turtl.forward(90)
turtl.done()

Output:

After running the above code we get the following output in which we can see that when the turtle has a default black color and when they move in the forward direction they change their color black to purple.

Python turtle color change
Python turtle color change

Python turtle color gradient

Before moving forward we have some piece of knowledge about gradient. The gradient is defined as an increase or decrease in the magnitude of a screen. We can also change the color of the screen according to the turtle gradient.

Code:

In the below code we will import the turtle module from which we can draw the turtle color gradient on the screen.

  • The turtle() method is used to make objects.
  • turtle.color(color) is used to give the color to the pen.
  • turtle.penup() is used to stop drawing color.
  • turtle.goto(-width/2, height/2) is used give the accurate position to the turtle.
  • turtle.pendown() is used to start drawing shapes.
  • turtle.forward(width * direction) is used to move the turtle in the forward direction.
from turtle import *
from turtle import Screen, Turtle
import turtle
turtle.title("Pythontpoint")
color = (0.70156, 0, 0.109218)  # (154, 0, 254)
target = (0.96328, 0.57656, 0.41250)  # (221, 122, 80)

win = Screen()
win.tracer(False)

width,height = win.window_width(), win.window_height()

deltas = [(hue - color[index]) / height for index, hue in enumerate(target)]

turtle = Turtle()
turtle.color(color)

turtle.penup()
turtle.goto(-width/2, height/2)
turtle.pendown()

direction = 1

for distance, y in enumerate(range(height//2, -height//2, -1)):

    turtle.forward(width * direction)
    turtle.color([color[i] + delta * distance for i, delta in enumerate(deltas)])
    turtle.sety(y)

    direction *= -1

win.tracer(True)
win.exitonclick()

Output:

After running the above code we get following code we get the following output in which we can see the color shade of the gradient is seen on the screen.

Python turtle color gradient
Python turtle color gradient

So, in this tutorial, we discussed Python Turtle Color and we have also covered different examples related to its implementation. Here is the list of examples that we have covered.

  • Python turtle color
  • Python turtle color RGB
  • Python turtle color chart
  • Python turtle color list
  • Python turtle color mode
  • Python turtle color fill
  • Python turtle color change
  • Python turtle color gradient

Do Follow: