Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What does the line turtle.circle(r,360,150) do? I can't figure it out

So I found this code online because I wanted to make my own so I like tried to understand what this person was doing by looking what all the different lines do, but i came across this line and I don’t know what it does. I can’t find anything about this online and if i try it out in a separate code it doesn’t work. It’s a piece of code from the game connect 4, and this is the function for drawing the circles. I’m talking about the

turtle.circle(r,360,150)

code. It’s in this little function:

def draw_circle(x,y,r,color): #draws a circle on x and y coordinates, with radius r and a color
    turtle.up() #penup
    turtle.goto(x,y-r) #turtle go to x and y-r coordinates so its a bit up
    turtle.seth(0) #sets angle to east so ->
    turtle.down() #pendown
    turtle.fillcolor(color) #starts to fill in a color
    turtle.begin_fill() #starts to fill the circle in the color
    turtle.circle(r,360,150) #turtle draws a circle with radius r and
    turtle.end_fill()

Excuse my comments on every line, I was trying to understand the code 🙂 I thought that the (r,360,150) was drawing a circle with radius r and on coordinates 360 and 150, but like I said before, I tried in in a separate file and it just makes a circle on 0,0. Can someone explain?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Make sure to read some documentation before you ask a question. StackOverflow community gets enraged if you don’t sometimes))

From python 3.10.4 documentation:

turtle.circle(radius, extent=None, steps=None)

Parameters:

  • radius – a number
  • extent – a number (or None)
  • steps – an integer (or None)

Draw a circle with given radius. The center is radius units left of the turtle; extent – an angle – determines which part of the circle is drawn. If extent is not given, draw the entire circle. If extent is not a full circle, one endpoint of the arc is the current pen position. Draw the arc in counterclockwise direction if radius is positive, otherwise in clockwise direction. Finally the direction of the turtle is changed by the amount of extent.

As the circle is approximated by an inscribed regular polygon, steps determines the number of steps to use. If not given, it will be calculated automatically. May be used to draw regular polygons.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading