stoneskin

learning coding with Scratch , Python and Java

index

02 Drawing with Python Turtle

2.2 Drawing Circle and color in Turtle

2.2.1 Turtle circle function

Below is a example of draw a circle with Turtle

import turtle
t=turtle.Pen()

# draw circle with radius 100
t.circle(100)

#when you click the screen, exit the python
turtle.exitonclick()

You will got a circle like below

circle

2.2.2 Drawing more circles

Below code will draw a 4 circles

code

please update your code in the 2.2.1 by add the highlight lines, you should get image of below: morecircle

2.3 Color in Turtle

2.3.1 Chose a color for your drawing

You could change the background color or the pen color with the code bgcolor() and pencolor()

code

and you will get a result like below: color

2.3.2 Color you could chose

2.3.3 Unlimited RGB Color

The RGB color system is one of the most well-known color systems in the world, and perhaps the most ubiquitous. As an additive color system, it combines Red, Green, and Blue light to create the colors we see on our TV screens, computer monitors, and smartphones.

In Python you could use RGB color to draw any color the computer supported.

The example of RGB color string in python is start with “#” and followed with 6 Hexadecimal number.

turtle.bgcolor("#6D43AB")
t = turtle.Pen()
t.pencolor("#006600")

You could use this tool to pick your RGB color: RGB Color Picker.

color picker

2.3.4 Try it yourself

Try below code to draw the color pattern code:2.3.4

import turtle
t = turtle.Pen()
turtle.bgcolor('black')
colors = ['red','yellow','blue','green']
for x in range(200):
    t.pencolor(colors[x%4])
    t.forward(x)
    t.left(91)

previous nxt