Ecode Five-pointed Star

ecode Five-pointed Star

We’ve had a thoroughly understanding to ecode, today let’s draw a five-pointed star there as the below picture states:

ecode Five-pointed Star

Principle:

It is made of 5 lines with the same length, each turning angle is a fixed value, how can we specify the angles?

ecode Five-pointed Star

1.In the middle of the five-pointed star is a regular pentagon, which can be divided into 3 triangles. The sum of the internal angles of each triangle is 180 degrees, 180*3=540 degrees

2.Each angle of the pentagon is 540/5=108 degrees

3.Calculate the angle of the triangle at the top of the five-pointed star from 108 degrees to be 180-108=72 degrees

4.Due to the symmetry of the triangle, the two base angles are the same, and the top angle is calculated as 180-72*2=56

5.Finally, the number of outer angles is 180-56=144. Suppose we start drawing from the lower right corner as the starting point, then when drawing to the top, we need to turn left 144 degrees and then draw the next line, the answer is 144 degrees, did you get it right?

Add the pen extension

Go to ecode at www.ecode.cnand create a new project to add the pen extension.

ecode Five-pointed Star

1.Choose the drawing pen.

ecode Five-pointed Star

You can choose to hide the sprite to get a wider view.

ecode Five-pointed Star

As mentioned in the above principle, we need to draw five lines and use a loop that is repeated 5 times. The length of each line is 100. The larger the number is, the larger the five-pointed star will be. Then turn left by 144 degrees. In addition, to ensure re-draw the picture every time we execute it, we need to erase all the patterns on the stage, let the brush return to the original point, and then drop the pen. Finally, in order not to draw the picture too fast, there is an interval, we add a 0.3 second loop, the complete code is shown below:

ecode Five-pointed Star

Next time let’s do a more complicated drawing:

ecode Five-pointed Star

If you have any ideas or opinions, please feel free to contact us via services@elecfreaks.com.