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:
It is made of 5 lines with the same length, each turning angle is a fixed value, how can we specify the angles?
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.
1.Choose the drawing pen.
You can choose to hide the sprite to get a wider view.
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:
Next time let’s do a more complicated drawing:
If you have any ideas or opinions, please feel free to contact us via firstname.lastname@example.org.
Share this post
About the Author
ELECFREAKS focuses on microbit and publishes interesting articles
- Micro bit supplier
- Wholesale Suppliers
- Micro bit tutorial
- Micro bit classroom pack
- Mcorbit Environment Monitoring
- TPBot car
- Micro:bit car
- AI Lens
- Micor:bit AI Lens
- Microbit gyroscope
- Micro:bit LEDs
- BBC micro:bit
- Micro:bit Manipulator
- Wukong board
- Micro:bit Motorcycle
- Nezha breakout
- Micro:bit DIY
- 360° servos
- AI Lens
- Retro Arcade