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?
>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.