Draw a Filled Circle in Python

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

  • How to depict the colored filled shapes using Python turtle?
  • How to modify the screen colour using Python turtle?
  • How to draw colored filled half-circle in python turtle
  • Draw colored filled circumvolve using Python turtle
  • How to draw a colored filled oval in python turtle
  • Depict colored filled square using Python turtle
  • Draw colored filled rectangle using Python turtle
  • Draw colored filled triangle using Python turtle
  • Depict colored filled star using Python turtle
  • Draw colored filled hexagon using Python turtle
  • Draw filled circle with a different color using Python turtle
  • Program to depict a chessboard using Python turtle
  • Draw 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 yous are new to Python turtle, and so check out Turtle programming in Python.

How to draw colored filled shapes in python turtle?

Let'due south understand the below steps how to describe the colored filled shapes using Python turtle with desired color-

  • As we know turtle is the inbuilt module in python and it provides drawing using a screen and turtle(pen).
  • To fill the desired colors in the shapes drawn by the turtle, we accept some functions.
  • We will use the role called fillcolor(), and nosotros accept to laissez passer the colour proper name or colour in the #RRGGBB format. R, Grand, and B are the hexadecimal numbers (0, 1, ii, 3, 4, 5, 6, vii, viii, nine, A, B, C, D, Eastward, F)
  • Now, nosotros accept to telephone call the office begin_fill() this function tells the turtle that all the upcoming closed objects need to make full with the given colors.
  • And once, we are done with the drawing, call end_fill() role. This role tells the turtle to stop filling the upcoming objects.

Read Python Turtle Write Office

How to change screen colour using Python turtle?

  • We accept already seen that past default turtle always opens up the screen with a white groundwork. But permit the states see how to change screen color using turtle in Python.
  • To change the color of the screen at any time first, we need to import turtle, then we can use the control "turtle.bgcolor(*args)".
  • The higher up method is used to set the background colour of the turtle screen.

Example:

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

In the below output, nosotros can meet the screen colour is changed to the desired greenish color in the new cartoon board.

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

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

  • Firstly, we need to import turtle, then nosotros tin create the turtle pen past declaring "tr = turtle.Turtle().
  • We volition employ the function called tr.color(), and so we can set the color by using "tr.color('blackness').
  • At present, we accept to call the role tr.begin_fill() this role volition showtime filling the colour inside the half-circumvolve. Also, the circle is of radius 130pixels and halfcircumvolve 180 degrees.
  • And in one case, we are done with the drawing, call the tr.end_fill() function. This function tells the turtle to terminate 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 halfcircumvolve 180 degrees with black 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

Let'due southdraw 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 function called fillcolor(), and then we tin can prepare the color past using "tr.fillcolor('black').
  • Now, nosotros have to call the function tr.begin_fill() this office will offset filling the color inside the circle.
  • And once, we are washed with the cartoon, call the tr.end_fill() office. This function tells the turtle to finish the filling of the color.

Instance:

          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 encounter the colored filled circle is drawn on the new cartoon board. It draws the circumvolve ofradius of 100units with black color filled inside. You can refer to the below screenshot.

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

How to depict a colored filled oval in python turtle

  • Firstly, we need 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 set turtle shape with the given shape.
  • Now, we have to call the function tr.begin_fill() this function volition start filling the colour within the circumvolve.
  • And one time, we are done with the drawing, call the tr.end_fill() function. This function tells the turtle to finish the filling of the colour.

Example:

          import turtle  tr = turtle.Turtle() tr.colour("black") tr.shape("circle") tr.begin_fill() tr.shapesize(10,v,2) tr.end_fill() turtle.washed()        

In this output, we can run into the colored filled oval is drawn on the new drawing board. The tr.shapesize(ten,5,2) is used to draw the oval, and 10 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 depict a colored filled oval in python turtle

Draw colored filled square in Python turtle

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

  • Firstly, we demand to import turtle, and so nosotros tin can create the turtle pen by declaring "tr = turtle.Turtle().
  • Here, we will use the fillcolor() function, and and so nosotros can prepare the colour by using "tr.fillcolor('red').
  • Now, nosotros will call the role tr.begin_fill() this function will start filling the color inside the square.
  • For cartoon the square we have used the forrad() and right() method.
  • And one time, nosotros are done with the filling of the colour, call the tr.end_fill() function. This role tells the turtle to cease the filling of the color.

Instance:

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

In this output, we can see that the colour is filled within the square in the new drawing board. You can refer to the below screenshot.

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

Draw colored filled rectangle in Python turtle

At present, we will see how to depict a colored filled rectangle using Python turtle.

  • Firstly, import turtle module, so we tin create the turtle pen past declaring "tr = turtle.Turtle().
  • Hither, nosotros will use the fillcolor() role, and so we can fix the color by using "tr.fillcolor('orangish').
  • Now, we will call the function tr.begin_fill() this function will start filling the colour inside the rectangle.
  • For drawing the rectangle we have used for loop, and the forward() and right() method.
  • And once, we are done with the filling of the colour, call the tr.end_fill() part. This role tells the turtle to end the filling of the colour.

Example:

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

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

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

Describe colored filled triangle in Python turtle

Let us see how to draw colored filled triangle using Python turtle.

  • Firstly, import turtle module, then nosotros tin can create the turtle pen past declaring "tr = turtle.Turtle().
  • Here, nosotros will employ the fillcolor() office, and then we can set up the colour past using "tr.fillcolor('light-green').
  • At present, we will phone call the function tr.begin_fill() this function volition start filling the colour within the triangle.
  • We have used for loop and also the forrard() and left() method is used to describe a triangle.
  • And once, nosotros are done with the filling of the color, telephone call the tr.end_fill() function. This part tells the turtle to end the filling of the color.

Example:

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

In this output, we tin see that the green color is filled inside the triangle, and it volition appear in the new window. You can refer to the below screenshot.

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

Describe colored filled star using Python turtle

Let us run acrosshow to draw colored filled star in Python using Turtle.

  • Firstly, import turtle module, and then we can create the turtle pen by declaring "tr = turtle.Turtle().
  • Here, we volition utilize the fillcolor() function, and so we tin can set the colour by using "tr.fillcolor('purple').
  • Now, nosotros will call the office tr.begin_fill() this function volition start filling the color inside the star.
  • We accept used for loop and as well the forrard() and left() method is used for drawing the star.
  • And once, we are done with the filling of the colour, call the tr.end_fill() function. This office tells the turtle to end the filling of the colour.

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.washed()        

In this output, we tin come across that the imperial color is filled within the star, and it volition appear in the new window.

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

Describe colored filled hexagon in Python turtle

Permit us see how to depict colored filled hexagon using Python turtle.

  • Firstly, import turtle module, then we can create the turtle pen past declaring "tr = turtle.Turtle().
  • Hither, we will utilize the fillcolor() function, and so we can set the colour past using "tr.fillcolor('violet').
  • Now, we will phone call the function tr.begin_fill() this office will start filling the color inside the hexagon.
  • We have used for loop and, too the forrard() and left() method is used for drawing the hexagon.
  • And once, nosotros are washed with the filling of the color, call the tr.end_fill() function. This function 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(6):     tr.frontward(120)     tr.left(60) tr.end_fill() turtle.done()        

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

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

Draw filled circumvolve with a different color using python turtle

Hither, we will see how to fill different colors in circle using Python turtle.

  • Firstly, import turtle module, and then we tin create the turtle pen past declaring "tr = turtle.Turtle().
  • Here, nosotros have created a listing of different colors which is "listing = ["violet","bluish","blood-red","green"]".
  • Also, nosotros have used the goto() method to move some distance.
  • The for loop volition iterate four times to draw a iv circle.
  • At present, we have to call the office tr.begin_fill() this function will start filling the color inside the circle.
  • To draws the circumvolve ofradius of 50we have used tr.circle() function.

Example:

          import turtle tr = turtle.Turtle() list = ["violet","blueish","red","greenish"] tr.up() tr.goto(200,0) for i in range(iv):     tr.down()     tr.begin_fill()     tr.fillcolor(list[i])     tr.circle(fifty)     tr.end_fill()     tr.upwardly()     tr.astern(100) tr.hideturtle() turtle.done()        

In this output, nosotros can run across that the different color is filled inside the circle in the new window. You lot can refer to the below screenshot.

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

Program to draw a chessboard in python turtle

For cartoon chess lath in Python using turtle, nosotros volition utilize the beneath steps:

  • Firstly, we have to import the turtle module, and 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 define a method to draw a square using the for loop to iterate in the given range. The tr.forwards(20) is used for moving the turtle in a forwards management past 20 units and tr.left(90) is used for turning the turtle in ninety degrees. This argument will be repeated 3 times to get the remaining boundaries of a chessboard.
  • To set the screen we have used the scr.setup() method in which widht=600 and height=600. The tr.speed(100) is the turtle object speed, yous can likewise change the speed accordingly.
  • And so the other for loop will command the drawing of a square in a row. So, we accept set the position for every row using "tr.setpos(0, twenty*i)".
  • Once more, we have used the for loop for 8 times and the if condition for alternative colour which is "black" and "white". Also, tr.fillcolor(col) volition start filling with the given color and tr.end_fill() will stop filling.
  • In the end, nosotros have used tr.hideturtle() to hide the turtle.

Example:

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

In this output, we can see that the chessboard is drawn in the new window. You lot can refer to the below screenshot.

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

Draw a tic tac toe lath using Python turtle

Let us see how to draw a tic tac toe lath in Python turtle.

  • Firstly, we have to import the turtle module, so we volition create a screen object by using "scr = turtle.Screen()".
  • For creating a turtle object we have used "tr = turtle.Turtle()".
  • Then ready up the turtle color to "bluish" and the width to "3".
  • Here, I have manually set the speed of the turtle to "2".
  • And then, for drawing the tic tac toe lath 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 square, I take used the method penup(), goto(), and pendown().

Example:

          import turtle scr = turtle.Screen() tr = turtle.Turtle() tr.colour("blueish") tr.width("three") tr.speed(2) for i in range(4):     tr.forrad(300)     tr.left(90) tr.penup() tr.goto(0,100) tr.pendown() tr.frontwards(300) tr.penup() tr.goto(0,200) tr.pendown() tr.forwards(300) tr.penup() tr.goto(100,0) tr.pendown() tr.left(90) tr.forward(300) tr.penup() tr.goto(200,0) tr.pendown() tr.forward(300) tr.hideturtle() turtle.done()        

In this output, nosotros tin see the tic tac toe lath in the new window. Yous can refer to the below screenshot.

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

Programme to draw a automobile in python turtle

Allow see how to draw a car in Python using turtle

  • For cartoon the machine in a python turtle, we accept to think well-nigh the shapes and structure of the car. The upper torso of the auto will be a rectangle, the tyres can exist drawn equally a circumvolve and the window and roof are similar to a trapezoid.
  • Firstly, nosotros accept to import the turtle module, so we volition create a turtle object "tr = turtle.Turtle()".
  • At present, nosotros volition draw a rectangular upper trunk of a auto past using "tr.color('#f62b35')" and "tr.fillcolor('#f62b35')" is used for filling the colour in motorcar.
  • Also, we accept used the penup(), goto(), pendown(), setheading() methods for cartoon a car.
  • To depict the tyres nosotros have used "tr.circle(20)" function and for filling the color in tyres we have used "tr.color('#000000')" and "tr.fillcolor(#000000′)".

Example:

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

In this output, we can see the colored filled car in the new window. You can refer to the below screenshot.

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

Python turtle draw letters

In this instance nosotros will see how to depict messages in python turtle

  • Firstly, import turtle module, then we tin can create the turtle pen by declaring "tr = turtle.Turtle().
  • Here, nosotros have used tr.colour("Blue") and tr.width(3) is used for line thickness.
  • For press the letter "M" we take to use for loop to make a semicircle. The backward() is used to move the pen in the astern direction by x unit.
  • The left() is used to rotate the pen in the antilock direction past an angle of x.

Example:

          import turtle ws = turtle.Screen() tr = turtle.Turtle() tr.color("Blue") tr.width(3) for x in range(180):     tr.backward(ane)     tr.left(1) tr.right(90) tr.forward(50) tr.right(90) tr.forward(30) tr.right(90) tr.frontward(50) turtle.done()        

In this output, nosotros can see that letter of the alphabet "M" is drawn in the new window. Yous tin 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, nosotros have used tr.color('red'). The style=(fontname, fontsize,fonttype) is used to ready the text in the given way.
  • The turtle.write() function is used to write text at the current turtle position.
  • To hibernate the turtle we accept used "tr.hideturtle()"

Example:

          import turtle tr = turtle.Turtle() tr.color('cerise') style = ('courier',thirty,'italic') tr.write('Welcome to Python Turtle',font=style,align='eye') tr.hideturtle() turtle.washed()        

In this output, we can see how the text is written in the new window. Y'all can refer to the beneath screenshot.

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

Describe rainbow benzene using python turtle

  • Firstly, import turtle module, then we can create the turtle object by declaring "tr = turtle.pen().
  • We fix the screen background color as 'black', 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%6]) is used for color in each step.
  • Here, tr.width(x/100 + 1) is used for increasing the width and the rotation will exist 59 degrees on the left.

Example:

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

In this output, we can see the rainbow benzene in the new window. You 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 run across how to create a brick wall in python turtle

  • To create a brick wall in python turtle, nosotros have to import the turtle and screen showtime.
  • Hither, Cursor_Size = twenty for drawing 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, 5) it is used to turn cursor into brick.

Instance:

          from turtle import Screen, Turtle Cursor_Size = xx scr = Screen() scr.setup(600, 600)  scr.setworldcoordinates(0, 0, 12, 24) scr.bgcolor('black') turtle = Turtle('square', visible=Fake) turtle.penup() turtle.speed(ten) turtle.color('black', 'crimson') turtle.shapesize(25 / Cursor_Size, l / Cursor_Size, 5) for y in range(24):     turtle.setposition(-0.v * (y % 2), y + 0.iii)     for x in range(13):         turtle.postage()         turtle.forwards(1) scr.mainloop()        

In this output, we can see that the brick wall is created in the new window. You 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 listing comprehension using if-else
  • Python Turtle Speed With Examples
  • Python Tkinter Stopwatch
  • Python read a binary file
  • Python Turtle Colors
  • Python enquire for user input
  • How to make a smiling face in python turtle
  • How to Convert Python cord 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 as well we saw Turtle programming in Python, also nosotros have covered these topics:

  • How to draw the colored filled shapes in python turtle?
  • How to alter the screen color in python turtle?
  • How to draw colored filled half-circle in python turtle
  • Draw colored filled circle in python turtle
  • How to depict a colored filled oval in python turtle
  • Draw colored filled square in python turtle
  • Draw colored filled rectangle in python turtle
  • Depict colored filled triangle in python turtle
  • Describe colored filled star in python turtle
  • Draw colored filled hexagon in python turtle
  • Depict filled circle with a different color using python turtle
  • Program to draw a chessboard in python turtle
  • Draw a tic tac toe lath in python turtle
  • Program to draw a car in python turtle
  • Python turtle draw messages
  • How to write text in python turtle
  • Depict rainbow benzene using python turtle
  • How to create a brick wall in python turtle

oliverpeed2001.blogspot.com

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

0 Response to "Draw a Filled Circle in Python"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel