Python Program to Draw a Circle

In this Python tutorial, nosotros will larn how to draw colored filled shapes using Python turtle with a few examples and also nosotros will cover these topics:

  • How to draw the colored filled shapes using Python turtle?
  • How to modify the screen color using Python turtle?
  • How to depict colored filled half-circle in python turtle
  • Draw colored filled circle using Python turtle
  • How to depict a colored filled oval in python turtle
  • Draw colored filled foursquare using Python turtle
  • Draw colored filled rectangle using Python turtle
  • Draw colored filled triangle using Python turtle
  • Draw colored filled star using Python turtle
  • Describe colored filled hexagon using Python turtle
  • Draw filled circle with a dissimilar color using Python turtle
  • Program to draw a chessboard using Python turtle
  • Describe a tic tac toe board using Python turtle
  • Program to draw a car using Python using turtle
  • Python turtle draw letters
  • Draw rainbow benzene using python turtle
  • How to create a brick wall in python turtle

If you are new to Python turtle, then cheque out Turtle programming in Python.

How to draw colored filled shapes in python turtle?

Let's understand the below steps how to depict the colored filled shapes using Python turtle with desired colour-

  • Equally we know turtle is the inbuilt module in python and information technology provides drawing using a screen and turtle(pen).
  • To fill the desired colors in the shapes fatigued by the turtle, nosotros have some functions.
  • We volition use the function chosen fillcolor(), and we take to pass the colour name or colour in the #RRGGBB format. R, Chiliad, and B are the hexadecimal numbers (0, 1, two, iii, 4, 5, vi, 7, viii, 9, A, B, C, D, E, F)
  • Now, nosotros have to call the function begin_fill() this function tells the turtle that all the upcoming closed objects need to fill with the given colors.
  • And once, we are done with the drawing, call end_fill() office. This function tells the turtle to stop filling the upcoming objects.

Read Python Turtle Write Function

How to change screen color using Python turtle?

  • We have already seen that by default turtle always opens up the screen with a white groundwork. Merely let united states of america see how to change screen color using turtle in Python.
  • To change the color of the screen at any fourth dimension showtime, nosotros need to import turtle, then nosotros tin can utilise the command "turtle.bgcolor(*args)".
  • The above method is used to set the background color of the turtle screen.

Example:

          import turtle  turtle.bgcolor("green") turtle.done()        

In the below output, we tin can run across the screen colour is inverse to the desired greenish color in the new cartoon board.

How to change the screen color in python turtle?
How to change the screen color in python turtle?

How to describe colored filled half-circle in python turtle

  • Firstly, we need to import turtle, then nosotros tin create the turtle pen by declaring "tr = turtle.Turtle().
  • We will apply the part called tr.color(), and then nosotros can set the color past using "tr.color('black').
  • Now, nosotros have to call the function tr.begin_fill() this function will beginning filling the color within the half-circle. Too, the circle is of radius 130pixels and one-halfcircle 180 degrees.
  • And once, nosotros are done with the drawing, call the tr.end_fill() office. This function tells the turtle to end the filling of the color.

Example:

          import turtle  tr = turtle.Turtle() tr.color("black") tr.begin_fill() tr.circle(130,180) tr.end_fill() tr.hideturtle() turtle.done()        

In this output, we can run across the colored filled half-circle is drawn on the new drawing board. It draws the circle of radius 130pixels and halfcircle 180 degrees with blackness color filled inside. You lot can refer to the below screenshot.

How to draw colored filled half-circle in python turtle
How to draw colored filled half-circle in python turtle

Draw colored filled circle in Python turtle

Permit'southwarddraw a colored filled circumvolve in python using turtle in Python.

  • Firstly, we need to import turtle, then we can create the turtle pen by declaring "tr = turtle.Turtle().
  • Nosotros will use the part called fillcolor(), and then we can fix the colour by using "tr.fillcolor('black').
  • Now, we accept to call the function tr.begin_fill() this function will start filling the color inside the circle.
  • And once, we are washed with the drawing, telephone call the tr.end_fill() function. This part tells the turtle to stop the filling of the color.

Example:

          import turtle tr = turtle.Turtle() tr.fillcolor('blackness') tr.begin_fill() tr.circle(100) tr.end_fill() turtle.done()        

In this output, we tin can see the colored filled circle is fatigued on the new cartoon board. It draws the circle ofradius of 100units with blackness color filled inside. You tin can refer to the below screenshot.

Draw colored filled circle in python turtle
Draw colored filled circle in python turtle

How to describe a colored filled oval in python turtle

  • Firstly, we demand to import turtle, then we can create the turtle pen by declaring "tr = turtle.Turtle().
  • The tr.colour() is used to return or fill colour and tr.shape() is used to prepare turtle shape with the given shape.
  • Now, nosotros have to call the function tr.begin_fill() this office will start filling the color inside the circle.
  • And once, we are washed with the drawing, call the tr.end_fill() role. This office tells the turtle to cease the filling of the color.

Example:

          import turtle  tr = turtle.Turtle() tr.colour("black") tr.shape("circle") tr.begin_fill() tr.shapesize(10,5,two) tr.end_fill() turtle.done()        

In this output, we can see the colored filled oval is drawn on the new drawing board. The tr.shapesize(10,5,ii) is used to draw the oval, and x is the width, 5 is the length, and 2 is the outline for the oval.

How to draw a colored filled oval in python turtle
How to describe a colored filled oval in python turtle

Draw colored filled square in Python turtle

Let united states talk over,how to draw colored filled square using Python turtle.

  • Firstly, nosotros need to import turtle, then we can create the turtle pen by declaring "tr = turtle.Turtle().
  • Here, we will apply the fillcolor() function, and then nosotros tin fix the color by using "tr.fillcolor('red').
  • Now, we will phone call the function tr.begin_fill() this function volition beginning filling the color inside the square.
  • For drawing the square nosotros have used the forward() and right() method.
  • And one time, we are washed with the filling of the color, call the tr.end_fill() role. This part tells the turtle to finish the filling of the color.

Example:

          import turtle tr = turtle.Turtle() tr.fillcolor('Cerise') tr.begin_fill() for i in range(iv):     tr.forward(150)     tr.right(ninety) tr.end_fill() turtle.done()        

In this output, we tin can see that the colour is filled inside the foursquare in the new drawing board. You lot can refer to the below screenshot.

Draw colored filled square in python turtle
Draw colored filled square in python turtle

Describe colored filled rectangle in Python turtle

Now, nosotros will encounter how to describe a colored filled rectangle using Python turtle.

  • Firstly, import turtle module, and then we tin can create the turtle pen past declaring "tr = turtle.Turtle().
  • Here, we volition utilize the fillcolor() function, and then we can prepare the color by using "tr.fillcolor('orange').
  • Now, we volition call the function tr.begin_fill() this function will start filling the color within the rectangle.
  • For drawing the rectangle we have used for loop, and the forrard() and correct() method.
  • And once, we are done with the filling of the color, phone call the tr.end_fill() function. This part tells the turtle to end the filling of the color.

Instance:

          import turtle tr = turtle.Turtle() tr.fillcolor('orangish') tr.begin_fill() for i in range(two):     tr.forward(250)     tr.correct(90)     tr.forward(150)     tr.right(90) tr.end_fill() turtle.washed()        

In this output, we can see that the orange color is filled inside the rectangle in the new window. You can refer to the below screenshot.

Draw colored filled rectangle in python turtle
Describe colored filled rectangle in python turtle

Describe colored filled triangle in Python turtle

Allow the states run across how to depict colored filled triangle using Python turtle.

  • Firstly, import turtle module, then we can create the turtle pen by declaring "tr = turtle.Turtle().
  • Hither, we will use the fillcolor() function, and then we can ready the color past using "tr.fillcolor('light-green').
  • Now, nosotros volition call the office tr.begin_fill() this part will start filling the color inside the triangle.
  • We have used for loop and too the forrard() and left() method is used to draw a triangle.
  • And one time, we are done with the filling of the color, call the tr.end_fill() office. This function tells the turtle to end the filling of the color.

Case:

          import turtle tr = turtle.Turtle() tr.fillcolor('green') tr.begin_fill() for i in range(three):     tr.forward(200)     tr.left(120) tr.end_fill() turtle.done()        

In this output, we can run into that the green color is filled inside the triangle, and it will appear in the new window. You tin can refer to the beneath screenshot.

Draw colored filled triangle in python turtle
Depict colored filled triangle in python turtle

Draw colored filled star using Python turtle

Allow us seehow to draw colored filled star in Python using Turtle.

  • Firstly, import turtle module, then we can create the turtle pen by declaring "tr = turtle.Turtle().
  • Hither, we will use the fillcolor() function, and so nosotros can set the color by using "tr.fillcolor('purple').
  • Now, nosotros will telephone call the function tr.begin_fill() this role volition start filling the color inside the star.
  • We have used for loop and also the forward() and left() method is used for drawing the star.
  • And one time, nosotros are done with the filling of the color, call the tr.end_fill() function. This function tells the turtle to cease the filling of the color.

Example:

          import turtle tr = turtle.Turtle() tr.fillcolor('purple') tr.begin_fill() for i in range(5):     tr.forward(250)     tr.left(144) tr.end_fill() turtle.done()        

In this output, we can see that the regal color is filled inside the star, and information technology volition appear in the new window.

Draw colored filled star in python turtle
Describe colored filled star in python turtle

Draw colored filled hexagon in Python turtle

Allow us see how to draw colored filled hexagon using Python turtle.

  • Firstly, import turtle module, then we can create the turtle pen by declaring "tr = turtle.Turtle().
  • Here, we volition use the fillcolor() function, and so we can set the color by using "tr.fillcolor('violet').
  • Now, we will phone call the function tr.begin_fill() this part will get-go filling the color inside the hexagon.
  • Nosotros have used for loop and, also the forwards() and left() method is used for cartoon the hexagon.
  • And once, we are washed with the filling of the colour, phone call the tr.end_fill() part. This office tells the turtle to end the filling of the color.

Example:

          import turtle tr = turtle.Turtle() tr.fillcolor('violet') tr.begin_fill() for i in range(vi):     tr.forward(120)     tr.left(lx) tr.end_fill() turtle.done()        

In this output, nosotros can see that violet colour is filled inside the hexagon in the new window. You tin can refer to the beneath screenshot.

Draw colored filled hexagon in python turtle
Depict colored filled hexagon in python turtle

Describe filled circle with a different colour using python turtle

Here, nosotros volition run into how to fill different colors in circle using Python turtle.

  • Firstly, import turtle module, then we tin can create the turtle pen by declaring "tr = turtle.Turtle().
  • Here, we take created a list of unlike colors which is "listing = ["violet","blue","red","dark-green"]".
  • Also, we have used the goto() method to motion some distance.
  • The for loop volition iterate 4 times to depict a 4 circumvolve.
  • At present, we have to call the office tr.begin_fill() this function volition start filling the color inside the circle.
  • To draws the circle ofradius of 50we have used tr.circle() function.

Case:

          import turtle tr = turtle.Turtle() list = ["violet","blueish","red","green"] tr.up() tr.goto(200,0) for i in range(iv):     tr.downwards()     tr.begin_fill()     tr.fillcolor(list[i])     tr.circle(50)     tr.end_fill()     tr.up()     tr.backward(100) tr.hideturtle() turtle.done()        

In this output, we tin see that the unlike color is filled within the circle in the new window. Y'all tin refer to the below screenshot.

Draw filled circle with a different color using python turtle
Draw filled circle with a different color using python turtle

Program to describe a chessboard in python turtle

For drawing chess board in Python using turtle, we will use the below steps:

  • Firstly, we have to import the turtle module, then we will create a screen object past using "scr = turtle.Screen()".
  • For creating a turtle object we accept used "tr = turtle.Turtle()".
  • Now, we will ascertain a method to describe a foursquare using the for loop to iterate in the given range. The tr.frontward(twenty) is used for moving the turtle in a forward direction by 20 units and tr.left(90) is used for turning the turtle in 90 degrees. This statement will be repeated iii times to get the remaining boundaries of a chessboard.
  • To set the screen nosotros have used the scr.setup() method in which widht=600 and height=600. The tr.speed(100) is the turtle object speed, you can also alter the speed accordingly.
  • And then the other for loop will control the cartoon of a foursquare in a row. So, we have fix the position for every row using "tr.setpos(0, 20*i)".
  • Again, we have used the for loop for viii times and the if condition for culling color which is "blackness" and "white". Also, tr.fillcolor(col) will start filling with the given color and tr.end_fill() will end filling.
  • In the end, we have used tr.hideturtle() to hide the turtle.

Case:

          import turtle scr = turtle.Screen() tr = turtle.Turtle() def describe():   for i in range(4):     tr.forward(20)     tr.left(90)   tr.forward(twenty) if __name__ == "__main__":     scr.setup(600, 600)     tr.speed(100)     for i in range(viii):       tr.up()       tr.setpos(0, 20*i)       tr.downward()       for j in range(8):         if(i + j)%two == 0:          col = 'black'         else:          col = 'white'         tr.fillcolor(col)         tr.begin_fill()         draw()         tr.end_fill()       tr.hideturtle() turtle.done()        

In this output, nosotros can see that the chessboard is drawn in the new window. You can refer to the beneath screenshot.

Program to draw a chessboard in python turtle
Program to draw a chessboard in python turtle

Draw a tic tac toe board using Python turtle

Allow us meet how to describe a tic tac toe board in Python turtle.

  • Firstly, nosotros take to import the turtle module, and and so we volition create a screen object by using "scr = turtle.Screen()".
  • For creating a turtle object nosotros have used "tr = turtle.Turtle()".
  • Then set up the turtle color to "blue" and the width to "iii".
  • Here, I take manually fix the speed of the turtle to "2".
  • And so, for drawing the tic tac toe board first we have to make an outer square and for loop is used to iterate. The "tr.forward(300)" is used for moving the turtle in a forrard direction by 300 units and "tr.left(90)" is used for turning the turtle in 90 degrees.
  • For inner lines of a foursquare, I have used the method penup(), goto(), and pendown().

Example:

          import turtle scr = turtle.Screen() tr = turtle.Turtle() tr.color("blue") tr.width("3") tr.speed(two) for i in range(four):     tr.forward(300)     tr.left(90) tr.penup() tr.goto(0,100) tr.pendown() tr.forrard(300) tr.penup() tr.goto(0,200) tr.pendown() tr.forward(300) tr.penup() tr.goto(100,0) tr.pendown() tr.left(90) tr.forrard(300) tr.penup() tr.goto(200,0) tr.pendown() tr.forward(300) tr.hideturtle() turtle.washed()        

In this output, we tin see the tic tac toe board in the new window. You can refer to the below screenshot.

Draw a tic tac toe board in python turtle
Describe a tic tac toe board in python turtle

Program to describe a car in python turtle

Let see how to draw a car in Python using turtle

  • For drawing the motorcar in a python turtle, nosotros have to retrieve well-nigh the shapes and construction of the car. The upper trunk of the car will exist a rectangle, the tyres tin can exist drawn equally a circle and the window and roof are similar to a trapezoid.
  • Firstly, we have to import the turtle module, then we will create a turtle object "tr = turtle.Turtle()".
  • Now, we volition describe a rectangular upper torso of a auto by using "tr.color('#f62b35')" and "tr.fillcolor('#f62b35')" is used for filling the colour in car.
  • Also, we have used the penup(), goto(), pendown(), setheading() methods for drawing a car.
  • To describe the tyres we have used "tr.circle(20)" function and for filling the colour in tyres we have used "tr.color('#000000')" and "tr.fillcolor(#000000′)".

Case:

          import turtle tr = turtle.Turtle() tr.color('#f62b35') tr.fillcolor('#f62b35') tr.penup() tr.goto(0,0) tr.pendown() tr.begin_fill() tr.forrard(370) tr.left(xc) tr.forward(50) tr.left(90) tr.forward(370) tr.left(90) tr.forrard(50) tr.left(90) tr.end_fill() tr.penup() tr.goto(100,fifty) tr.pendown() tr.setheading(45) tr.forward(70) tr.setheading(0) tr.forrard(100) tr.setheading(-45) tr.forrad(lxx) tr.setheading(ninety) tr.penup() tr.goto(200, 50) tr.pendown() tr.forward(49.50) tr.penup() tr.goto(100, -ten) tr.pendown() tr.color('#000000') tr.fillcolor('#000000') tr.begin_fill() tr.circle(20) tr.end_fill() tr.penup() tr.goto(300, -x) tr.pendown() tr.color('#000000') tr.fillcolor(#000000') tr.begin_fill() tr.circle(xx) tr.end_fill() tr.hideturtle() turtle.done()        

In this output, we tin run into the colored filled car in the new window. You tin refer to the below screenshot.

Program to draw a car in python turtle
Program to draw a car in python turtle

Python turtle depict letters

In this example we volition see how to depict letters in python turtle

  • Firstly, import turtle module, then nosotros can create the turtle pen by declaring "tr = turtle.Turtle().
  • Hither, we have used tr.colour("Blue") and tr.width(3) is used for line thickness.
  • For printing the letter "G" nosotros have to use for loop to make a semicircle. The backward() is used to motion the pen in the backward direction by 10 unit of measurement.
  • The left() is used to rotate the pen in the antilock direction by an angle of x.

Case:

          import turtle ws = turtle.Screen() tr = turtle.Turtle() tr.color("Blue") tr.width(three) for x in range(180):     tr.backward(one)     tr.left(i) tr.right(xc) tr.forward(l) tr.right(xc) tr.frontward(30) tr.right(90) tr.forward(50) turtle.done()        

In this output, we tin can meet that letter "M" is drawn in the new window. Yous can refer to the beneath screenshot.

Python turtle draw letters
Python turtle draw letters

How to write text in python turtle

  • Firstly, import turtle module, then we can create the turtle pen by declaring "tr = turtle.Turtle().
  • Here, we have used tr.colour('red'). The mode=(fontname, fontsize,fonttype) is used to set the text in the given style.
  • The turtle.write() function is used to write text at the current turtle position.
  • To hide the turtle we take used "tr.hideturtle()"

Instance:

          import turtle tr = turtle.Turtle() tr.colour('red') style = ('courier',30,'italic') tr.write('Welcome to Python Turtle',font=style,marshal='center') tr.hideturtle() turtle.done()        

In this output, nosotros tin can see how the text is written in the new window. Yous can refer to the below screenshot.

How to write text in python turtle
How to write text in python turtle

Depict rainbow benzene using python turtle

  • Firstly, import turtle module, then we tin create the turtle object by declaring "tr = turtle.pen().
  • We gear up the screen background color every bit 'blackness', and the speed of the turtle is '0' which is the fastest.
  • Afterward that for loop is used and the range is 180.
  • The tr.pencolor(colors[x%vi]) is used for color in each step.
  • Here, tr.width(x/100 + 1) is used for increasing the width and the rotation will be 59 degrees on the left.

Example:

          import turtle colors = ['royal', 'indigo', 'blue', 'green', 'yellow', 'orange'] tr = turtle.pen() turtle.bgcolor('black') tr.speed(0) for 10 in range(180):     tr.pencolor(colors[x%6])     tr.width(x/100 + 1)     tr.forward(ten)     tr.left(59) turtle.done()        

In this output, nosotros tin can see the rainbow benzene in the new window. Y'all can refer to the below screenshot.

Draw rainbow benzene using python turtle
Draw rainbow benzene using python turtle

How to create a brick wall in python turtle

Let encounter how to create a brick wall in python turtle

  • To create a brick wall in python turtle, we have to import the turtle and screen first.
  • Here, Cursor_Size = 20 for cartoon the brick. The scr.setup(600, 600) is used to setup the screen size.
  • scr.setworldcoordinates(0, 0, 12, 24) is used to setup the user define coordinate based on bricks.
  • turtle.shapesize(25 / Cursor_Size, 50 / Cursor_Size, five) information technology is used to plough cursor into brick.

Instance:

          from turtle import Screen, Turtle Cursor_Size = 20 scr = Screen() scr.setup(600, 600)  scr.setworldcoordinates(0, 0, 12, 24) scr.bgcolor('black') turtle = Turtle('square', visible=Faux) turtle.penup() turtle.speed(10) turtle.colour('black', 'red') turtle.shapesize(25 / Cursor_Size, 50 / Cursor_Size, 5) for y in range(24):     turtle.setposition(-0.v * (y % 2), y + 0.three)     for x in range(13):         turtle.stamp()         turtle.forrad(1) scr.mainloop()        

In this output, nosotros can see that the brick wall is created in the new window. Yous can refer to the below screenshot.

How to create a brick wall in python turtle
How to create a brick wall in python turtle

You may like the following Python tutorials:

  • Python list comprehension using if-else
  • Python Turtle Speed With Examples
  • Python Tkinter Stopwatch
  • Python read a binary file
  • Python Turtle Colors
  • Python ask for user input
  • How to make a grinning face in python turtle
  • How to Convert Python string to byte array with Examples
  • Python pass by reference or value with examples
  • Python select from a list
  • Python copy file
  • Python File methods

In this tutorial we have learned how to describe colored filled shapes in python using turtle and also we saw Turtle programming in Python, also we have covered these topics:

  • How to draw the colored filled shapes in python turtle?
  • How to change the screen color in python turtle?
  • How to draw colored filled half-circle in python turtle
  • Depict colored filled circle in python turtle
  • How to draw a colored filled oval in python turtle
  • Draw colored filled foursquare in python turtle
  • Draw colored filled rectangle in python turtle
  • Draw colored filled triangle in python turtle
  • Describe colored filled star in python turtle
  • Draw colored filled hexagon in python turtle
  • Draw filled circumvolve with a different color using python turtle
  • Program to draw a chessboard in python turtle
  • Draw a tic tac toe board in python turtle
  • Program to draw a auto in python turtle
  • Python turtle draw letters
  • How to write text in python turtle
  • Draw rainbow benzene using python turtle
  • How to create a brick wall in python turtle

freemansweves.blogspot.com

Source: https://pythonguides.com/draw-colored-filled-shapes-using-python-turtle/

0 Response to "Python Program to Draw a Circle"

Postar um comentário

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel