We draw a basic Trefoil shape in this project. Can you draw two Trefoils shapes to form a ring? All tricks are okay as long as they work!
Trefoil Shape with Python and Turtle
Trefoil, comes from Lantin, means three-leaved plant. It is a shape used in architecture and Christian symbolism. For more details about this shape checkout this Wikipedia article.
Hint: This shape is composed of three arcs with extent of 240 degrees.
Pacman Shape with Python and Turtle
Draw a pacman shape as shown. The opening angle of the mouth is 60 degrees. You can try to draw other opening angles.
Hint: Start from the center, draw a line, draw an arc, go to the center.
Parallelogram with Python and Turtle
Draw a simple parallelogram with Python and Turtle. It can have any angles and any side lengths.
Sun with Circle and Isosceles Triangles
Draw a sun shape with a circle and evenly space isosceles triangles surrounding the circle. You may need to use trigonometry to draw this shape. You can also color the circle and the triangles.
Dog Bone Shape with Python and Turtle
Draw a simple dog bone shape with Python and Turtle. This shape contains 2 lines and 4 arcs. You can draw the shape in one stroke without lifting the pen up. You can also fill the bone with the a color of your choice.
You can post your solution in the comment section.
Throbbing Heart Animation with Python and Turtle (Source Code)
Animate a throbbing heart. Check out this simple heart drawing tutorial if you need help.
Source Code:
import turtle
import math
screen = turtle.Screen()
screen.title('Heart Animation - PythonTurtle.Academy')
screen.setup(1000,1000)
screen.setworldcoordinates(-1000,-1000,1000,1000)
turtle.speed(0)
turtle.hideturtle()
screen.tracer(0,0)
turtle.color('red')
def draw_heart(alpha,d):
r = d/math.tan(math.radians(180-alpha/2))
turtle.up()
turtle.goto(0,-d*math.cos(math.radians(45)))
turtle.seth(90-(alpha-180))
turtle.down()
turtle.begin_fill()
turtle.fd(d)
turtle.circle(r,alpha)
turtle.left(180)
turtle.circle(r,alpha)
turtle.fd(d)
turtle.end_fill()
a = 220
sign = -1
def animate():
global a,sign
turtle.clear()
draw_heart(a,1000)
screen.update()
a += sign
if a < 215:
sign = -sign
elif a > 220:
sign = -sign
screen.ontimer(animate,50)
animate()
Tutorial: How to Draw a Simple Heart Shape with Python and Turtle
The figure above shows, we can draw a simple heart shape with 4 segments: 2 lines and 2 arcs. We can continuously draw these 4 segments without lifting up the pen.
We start from the bottom tip of the heart. The heading for the blue line is 45 degrees. The second segment is 225 degree arc. After initial 45 degree heading and 225 degree turn, the heading of the turtle will be a 45+225=270 degrees, which is facing down perfectly. The rest of the two segments are symmetric to the first two. All we need to do is just turn the Turtle by 180 degrees before drawing the 3rd segment.
The next step is to figure out the ratio of blue segment and the radius of the arc. In the figure above, a triangle formed by two black lines and the blue line is a right triangle. The angle between two black lines is (360-225)/2 = 67.5 degrees, where 225 is the degree of the arc. Therefore, the ratio of blue line segment and the radius equals to tangent(67.5).
Here is the code:
import turtle
import math
turtle.color('red')
d = 800
r = d/math.tan(math.radians(67.5))
turtle.up()
turtle.goto(0,-600)
turtle.seth(45)
turtle.down()
turtle.fd(d)
turtle.circle(r,225)
turtle.left(180)
turtle.circle(r,225)
turtle.fd(d)
You can easily draw a filled heart by calling begin_fill() and end_fill() functions:
turtle.color('red')
d = 800
r = d/math.tan(math.radians(67.5))
turtle.up()
turtle.goto(0,-600)
turtle.seth(45)
turtle.begin_fill()
turtle.down()
turtle.fd(d)
turtle.circle(r,225)
turtle.left(180)
turtle.circle(r,225)
turtle.fd(d)
turtle.end_fill()
Related Projects:
Five Golden Fractal Trees
Based on golden fractal tree project, draw the following shape that contains 5 golden fractal trees.
Golden Fractal Tree with Python Turtle (Source Code)
Golden Fractal Tree is a tree based on Golden Ratio. The golden fractal tree contains the main branch and three smaller golden fractal trees: the first branch turns left by 72 degrees with ratio of main branch to the parent’s main branch = 2-golden_ratio; the second branch have the same the direction as the parent with ratio of main branch to the parent’s main branch = golden_ratio-1; the first branch turns right by 72 degrees with ratio of main branch to the parent’s main branch = 2-golden_ratio. For more details on golden fractal tree, please check out this web page.
Source Code:
import turtle
import math
screen = turtle.Screen()
screen.title('Golden Fractal Tree - PythonTurtle.Academy')
screen.setup(1000,1000)
screen.setworldcoordinates(-1000,-1000,1000,1000)
turtle.speed(0)
turtle.hideturtle()
turtle.tracer(0,0)
golden_ratio = (1+5**0.5)/2
def golden_fractal_tree(x,y,direction,length):
turtle.up()
turtle.goto(x,y)
turtle.seth(direction)
turtle.pensize(math.log(length,2)/3)
if length<10: turtle.color('forest green')
else: turtle.color('gray')
turtle.down()
turtle.fd(length)
if length < 3: return
cx,cy = turtle.xcor(), turtle.ycor()
golden_fractal_tree(cx,cy,direction+72,(2-golden_ratio)*length)
golden_fractal_tree(cx,cy,direction-72,(2-golden_ratio)*length)
golden_fractal_tree(cx,cy,direction,(golden_ratio-1)*length)
golden_fractal_tree(0,-900,90,700)
turtle.update()