Draw a Circle in Python Scipy

In this Python tutorial, we will learn how to draw colored filled shapes using Python turtle with a few examples and as well nosotros volition encompass these topics:

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

If yous are new to Python turtle, then check out Turtle programming in Python.

How to draw colored filled shapes in python turtle?

Let's understand the below steps how to draw 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 make full the desired colors in the shapes drawn by the turtle, we take some functions.
  • We will use the function called fillcolor(), and nosotros accept to pass the color proper noun or color in the #RRGGBB format. R, G, and B are the hexadecimal numbers (0, 1, 2, iii, 4, 5, 6, vii, 8, 9, A, B, C, D, Due east, F)
  • Now, we have to phone call the role begin_fill() this function tells the turtle that all the upcoming closed objects need to make full with the given colors.
  • And once, nosotros are washed with the drawing, call end_fill() role. This function tells the turtle to stop filling the upcoming objects.

Read Python Turtle Write Function

How to alter screen color using Python turtle?

  • We have already seen that by default turtle always opens upwards the screen with a white background. Simply permit us run across how to change screen color using turtle in Python.
  • To change the color of the screen at any time first, nosotros need to import turtle, and so we can use the control "turtle.bgcolor(*args)".
  • The in a higher place method is used to set the groundwork color of the turtle screen.

Example:

          import turtle  turtle.bgcolor("dark-green") turtle.washed()        

In the below output, we tin come across the screen color is changed to the desired light-green color in the new drawing lath.

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

How to depict colored filled one-half-circumvolve in python turtle

  • Firstly, we demand to import turtle, then we can create the turtle pen by declaring "tr = turtle.Turtle().
  • Nosotros will use the function called tr.colour(), and then we tin can set the color by using "tr.colour('black').
  • Now, we take to call the part tr.begin_fill() this part will start filling the color inside the half-circle. Also, the circle is of radius 130pixels and halfcircumvolve 180 degrees.
  • And once, we are washed with the drawing, call the tr.end_fill() function. This function tells the turtle to end the filling of the color.

Instance:

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

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

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

Draw colored filled circle in Python turtle

Let'sdescribe a colored filled circumvolve in python using turtle in Python.

  • Firstly, we need to import turtle, then we can create the turtle pen past declaring "tr = turtle.Turtle().
  • We volition use the role called fillcolor(), and and then we can set the color past using "tr.fillcolor('black').
  • Now, we accept to call the function tr.begin_fill() this function will commencement filling the colour within the circle.
  • And once, we are done with the drawing, telephone call the tr.end_fill() function. This function tells the turtle to end the filling of the color.

Instance:

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

In this output, we tin can see the colored filled circle is drawn on the new drawing board. It draws the circle ofradius of 100units with black color filled inside. You lot can refer to the beneath screenshot.

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

How to draw 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.color() is used to return or fill color and tr.shape() is used to set turtle shape with the given shape.
  • Now, we have to phone call the function tr.begin_fill() this function will start filling the color inside the circle.
  • And once, we are done with the cartoon, call the tr.end_fill() function. This role tells the turtle to cease the filling of the colour.

Instance:

          import turtle  tr = turtle.Turtle() tr.color("black") tr.shape("circumvolve") tr.begin_fill() tr.shapesize(10,5,2) tr.end_fill() turtle.done()        

In this output, we tin can come across the colored filled oval is drawn on the new drawing lath. The tr.shapesize(10,v,2) is used to depict the oval, and x is the width, v is the length, and 2 is the outline for the oval.

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

Draw colored filled square in Python turtle

Permit u.s.a. discuss,how to draw colored filled square using Python turtle.

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

Instance:

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

In this output, we can see that the color is filled inside the square in the new drawing board. Y'all tin can refer to the below screenshot.

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

Depict colored filled rectangle in Python turtle

At present, we volition come across how to draw a colored filled rectangle using Python turtle.

  • Firstly, import turtle module, then we tin create the turtle pen past declaring "tr = turtle.Turtle().
  • Here, we will utilise the fillcolor() part, and and then we tin can set the color by using "tr.fillcolor('orange').
  • Now, nosotros will phone call the function tr.begin_fill() this role will commencement filling the colour inside the rectangle.
  • For cartoon the rectangle we take 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() role. This role tells the turtle to cease the filling of the colour.

Example:

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

In this output, we can come across that the orangish color is filled within the rectangle in the new window. You tin refer to the beneath screenshot.

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

Draw colored filled triangle in Python turtle

Let u.s.a. see how to describe colored filled triangle using Python turtle.

  • Firstly, import turtle module, then we can create the turtle pen by declaring "tr = turtle.Turtle().
  • Here, nosotros will use the fillcolor() function, so we tin ready the color past using "tr.fillcolor('green').
  • Now, we will phone call the part tr.begin_fill() this function will starting time filling the color inside the triangle.
  • We have used for loop and as well the forwards() and left() method is used to depict a triangle.
  • And once, we are done with the filling of the colour, call the tr.end_fill() function. This function tells the turtle to finish the filling of the color.

Example:

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

In this output, we tin see that the light-green color is filled inside the triangle, and it will appear in the new window. Yous can refer to the beneath screenshot.

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

Draw colored filled star using Python turtle

Let us run intohow to describe colored filled star in Python using Turtle.

  • Firstly, import turtle module, so nosotros can create the turtle pen by declaring "tr = turtle.Turtle().
  • Hither, we will use the fillcolor() function, and and then we can gear up the colour past using "tr.fillcolor('purple').
  • Now, we volition call the function tr.begin_fill() this function will start filling the color within the star.
  • Nosotros take used for loop and likewise the forrad() and left() method is used for drawing the star.
  • And in one case, we are washed with the filling of the colour, phone call the tr.end_fill() role. This function tells the turtle to end the filling of the color.

Case:

          import turtle tr = turtle.Turtle() tr.fillcolor('majestic') 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 it will appear in the new window.

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

Draw colored filled hexagon in Python turtle

Permit united states of america see how to draw colored filled hexagon using Python turtle.

  • Firstly, import turtle module, and so we can create the turtle pen by declaring "tr = turtle.Turtle().
  • Here, we will employ the fillcolor() function, and and then we can set the color past using "tr.fillcolor('violet').
  • Now, we will phone call the function tr.begin_fill() this role will start filling the color within the hexagon.
  • We have used for loop and, likewise the forward() and left() method is used for drawing the hexagon.
  • And one time, nosotros are done with the filling of the color, phone 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('violet') tr.begin_fill() for i in range(vi):     tr.forward(120)     tr.left(sixty) 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 circle with a different colour using python turtle

Here, we will run into how to make full different colors in circle using Python turtle.

  • Firstly, import turtle module, then we can create the turtle pen by declaring "tr = turtle.Turtle().
  • Here, nosotros accept created a list of unlike colors which is "list = ["violet","blue","red","light-green"]".
  • Besides, nosotros have used the goto() method to move some distance.
  • The for loop volition iterate four times to draw a 4 circle.
  • At present, we have to telephone call the part tr.begin_fill() this function will get-go filling the colour inside the circle.
  • To draws the circle ofradius of fiftynosotros have used tr.circumvolve() function.

Instance:

          import turtle tr = turtle.Turtle() list = ["violet","bluish","cerise","green"] tr.upward() tr.goto(200,0) for i in range(4):     tr.downwardly()     tr.begin_fill()     tr.fillcolor(list[i])     tr.circumvolve(l)     tr.end_fill()     tr.upwardly()     tr.backward(100) tr.hideturtle() turtle.done()        

In this output, nosotros can see that the different colour is filled within the circle in the new window. You tin can refer to the below screenshot.

Draw filled circle with a different color using python turtle
Describe filled circle with a unlike colour using python turtle

Program to draw a chessboard in python turtle

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

  • Firstly, nosotros have to import the turtle module, and then nosotros will create a screen object by using "scr = turtle.Screen()".
  • For creating a turtle object we have used "tr = turtle.Turtle()".
  • Now, we volition define a method to draw a square using the for loop to iterate in the given range. The tr.frontward(20) is used for moving the turtle in a forward direction by twenty units and tr.left(90) is used for turning the turtle in 90 degreesouth. This statement will be repeated 3 times to go the remaining boundaries of a chessboard.
  • To ready 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, y'all can likewise modify the speed appropriately.
  • And so the other for loop will control the drawing of a square in a row. So, nosotros have set the position for every row using "tr.setpos(0, 20*i)".
  • Again, nosotros have used the for loop for eight times and the if status for alternative color which is "black" and "white". Also, tr.fillcolor(col) volition start filling with the given colour and tr.end_fill() will end filling.
  • In the cease, we have used tr.hideturtle() to hibernate the turtle.

Instance:

          import turtle scr = turtle.Screen() tr = turtle.Turtle() def draw():   for i in range(iv):     tr.frontward(20)     tr.left(90)   tr.forwards(20) if __name__ == "__main__":     scr.setup(600, 600)     tr.speed(100)     for i in range(8):       tr.upwardly()       tr.setpos(0, 20*i)       tr.down()       for j in range(viii):         if(i + j)%ii == 0:          col = 'black'         else:          col = 'white'         tr.fillcolor(col)         tr.begin_fill()         describe()         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 below screenshot.

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

Describe a tic tac toe board using Python turtle

Let usa encounter how to draw a tic tac toe board in Python turtle.

  • Firstly, we have to import the turtle module, and then we will create a screen object by using "scr = turtle.Screen()".
  • For creating a turtle object we have used "tr = turtle.Turtle()".
  • So ready the turtle color to "blue" and the width to "iii".
  • Here, I have manually set the speed of the turtle to "2".
  • So, for drawing the tic tac toe board outset nosotros 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 frontwards direction by 300 units and "tr.left(xc)" is used for turning the turtle in 90 degrees.
  • For inner lines of a square, I have used the method penup(), goto(), and pendown().

Case:

          import turtle scr = turtle.Screen() tr = turtle.Turtle() tr.color("blue") tr.width("3") tr.speed(two) for i in range(4):     tr.forward(300)     tr.left(xc) tr.penup() tr.goto(0,100) tr.pendown() tr.forwards(300) tr.penup() tr.goto(0,200) tr.pendown() tr.forward(300) tr.penup() tr.goto(100,0) tr.pendown() tr.left(ninety) tr.frontwards(300) tr.penup() tr.goto(200,0) tr.pendown() tr.forward(300) tr.hideturtle() turtle.done()        

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

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

Program to depict a car in python turtle

Let meet how to describe a motorcar in Python using turtle

  • For drawing the car in a python turtle, we have to think about the shapes and structure of the car. The upper body of the car will be a rectangle, the tyres can be drawn as a circle and the window and roof are similar to a trapezoid.
  • Firstly, nosotros have to import the turtle module, and then we will create a turtle object "tr = turtle.Turtle()".
  • Now, nosotros will depict a rectangular upper body of a motorcar by using "tr.color('#f62b35')" and "tr.fillcolor('#f62b35')" is used for filling the color in car.
  • Likewise, we accept used the penup(), goto(), pendown(), setheading() methods for drawing a car.
  • To draw the tyres we have used "tr.circle(20)" function and for filling the colour in tyres nosotros have used "tr.color('#000000')" and "tr.fillcolor(#000000′)".

Instance:

          import turtle tr = turtle.Turtle() tr.color('#f62b35') tr.fillcolor('#f62b35') tr.penup() tr.goto(0,0) tr.pendown() tr.begin_fill() tr.forward(370) tr.left(90) tr.forrard(50) tr.left(90) tr.frontwards(370) tr.left(90) tr.frontward(50) tr.left(90) tr.end_fill() tr.penup() tr.goto(100,50) tr.pendown() tr.setheading(45) tr.forwards(70) tr.setheading(0) tr.forward(100) tr.setheading(-45) tr.forward(70) tr.setheading(xc) tr.penup() tr.goto(200, 50) tr.pendown() tr.forward(49.l) tr.penup() tr.goto(100, -x) tr.pendown() tr.color('#000000') tr.fillcolor('#000000') tr.begin_fill() tr.circumvolve(xx) tr.end_fill() tr.penup() tr.goto(300, -10) tr.pendown() tr.color('#000000') tr.fillcolor(#000000') tr.begin_fill() tr.circle(20) tr.end_fill() tr.hideturtle() turtle.washed()        

In this output, nosotros can see the colored filled machine in the new window. Yous tin can refer to the below screenshot.

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

Python turtle describe letters

In this example nosotros will see how to depict letters in python turtle

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

Instance:

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

In this output, nosotros can run across that letter "G" is drawn in the new window. Y'all can refer to the below screenshot.

Python turtle draw letters
Python turtle depict letters

How to write text in python turtle

  • Firstly, import turtle module, then we can create the turtle pen past declaring "tr = turtle.Turtle().
  • Hither, we accept used tr.color('ruddy'). The fashion=(fontname, fontsize,fonttype) is used to set the text in the given way.
  • The turtle.write() office is used to write text at the electric current turtle position.
  • To hide the turtle we have used "tr.hideturtle()"

Case:

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

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

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

Draw rainbow benzene using python turtle

  • Firstly, import turtle module, then nosotros can create the turtle object by declaring "tr = turtle.pen().
  • We set the screen groundwork colour as 'black', and the speed of the turtle is '0' which is the fastest.
  • After that for loop is used and the range is 180.
  • The tr.pencolor(colors[x%6]) is used for color in each pace.
  • Here, tr.width(10/100 + 1) is used for increasing the width and the rotation volition exist 59 degrees on the left.

Instance:

          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%half dozen])     tr.width(x/100 + i)     tr.forward(x)     tr.left(59) turtle.done()        

In this output, we can meet the rainbow benzene in the new window. Yous tin 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 come across 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 commencement.
  • Here, Cursor_Size = 20 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, v) it is used to turn cursor into brick.

Example:

          from turtle import Screen, Turtle Cursor_Size = twenty scr = Screen() scr.setup(600, 600)  scr.setworldcoordinates(0, 0, 12, 24) scr.bgcolor('black') turtle = Turtle('foursquare', visible=False) turtle.penup() turtle.speed(10) turtle.color('black', 'ruddy') turtle.shapesize(25 / Cursor_Size, 50 / Cursor_Size, 5) for y in range(24):     turtle.setposition(-0.5 * (y % ii), y + 0.iii)     for x in range(13):         turtle.stamp()         turtle.forward(i) scr.mainloop()        

In this output, we can see that the brick wall is created in the new window. You can refer to the beneath screenshot.

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

You lot 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 inquire for user input
  • How to make a smiling 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 nosotros have learned how to draw colored filled shapes in python using turtle and also we saw Turtle programming in Python, besides we have covered these topics:

  • How to draw the colored filled shapes in python turtle?
  • How to change the screen colour in python turtle?
  • How to depict colored filled half-circle in python turtle
  • Draw colored filled circle in python turtle
  • How to draw a colored filled oval in python turtle
  • Draw colored filled foursquare in python turtle
  • Depict colored filled rectangle in python turtle
  • Draw colored filled triangle in python turtle
  • Draw colored filled star in python turtle
  • Draw colored filled hexagon in python turtle
  • Describe 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 letters
  • How to write text in python turtle
  • Draw rainbow benzene using python turtle
  • How to create a brick wall in python turtle

nunnallashom.blogspot.com

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

0 Response to "Draw a Circle in Python Scipy"

แสดงความคิดเห็น

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel