Python and Turtle custom functions,Difficulty Level 2,math,python,Tutorial Three Overlapping Circles with Python and Turtle (Tutorial)

Three Overlapping Circles with Python and Turtle (Tutorial)

Draw the following overlapping circles. Please note that each circle passes through the center of the other two circles.

Three Overlapping Circles

Solution

We observe that the centers of the three circles form an equilateral triangle and the length of the equilateral triangle is the radius of the circle. So, the first step is to figure out the coordinates of the vertices of the equilateral triangle (with some math), and then draw three circles given the these three coordinates as the centers. So, it will be helpful to create a function that draws circle based on the center and radius. The following is the source code:

import turtle

screen = turtle.Screen()
screen.title('Three Circles - PythonTurtle.Academy')
screen.setup(1000,1000)
turtle.hideturtle()
turtle.speed(0)

def draw_circle(x,y,radius):
  turtle.up()
  turtle.goto(x,y-radius)
  turtle.seth(0)
  turtle.down()
  turtle.circle(radius,steps=360)

r = 150
draw_circle(0,r,r*3**0.5)
draw_circle(-r/2*3**0.5,-r/2,r*3**0.5)
draw_circle(r/2*3**0.5,-r/2,r*3**0.5)

What’s next?

Draw any number of overlapping circles.

Tags:

Related Post