Skip to content

leyaoliatan/Draw-a-heart-shape

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 

Repository files navigation

Draw-a-heart-shape

*Note, you may download the entire code (turtle.py) in the 'master' branch.

Turtle is a cute and amazing library in python. Let's draw a heart shape with turtle. This will be my very first project here.

Drawing a heart shape is not something new. There are lots of exsiting code for referring (e.g. geeks for geeks) However, when checking such example codes, my concern is that how did they get such precise parameters? It's not very intuitive. So this project is a simple version of deriving the parameters:

  • started form the bottom, draw a line which forms a 45 degree angle with positive x-axis.

image

  • the upper part is an arc, so for each move, we could turn right for one single degree. Moving forward for 180 degree, we will get a semicircle. But what is the perimeter of this semicircle? Let's derive with basic geometry. If the length of the straight line is 135, then the length of the semicircle would be 720/3.14 approximately.

image

  • Now repeat the steps for the right-hand side with merely changing the directions.

image

The detailed code is shown in turtle.py

p.s. Click here to check the Chinese version

About

Let's draw a heart shape with turtle!❤️

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages