A pyramid is a tetrahedron with an upper tip and a lower part. Its cross-section is a triangle. Rectangular bricks can be stacked into a large triangle to represent the pyramid.
The following introduces the use of Scratch to draw pyramids.
1. Define "bricks" building blocks
2. Define 5 variables
Click [Variables] on the left side of Scratch --> Create the following 5 variables
- The lower left corner of the current brick X
- The lower left corner of the current brick Y
- Pyramid layers
- Brick length
- The brick width
is shown in figure (3):
3. Define the building block "Adjust the length and width of the bricks"
Since the size of the entire canvas is 480x360, the total length of the bricks on each layer cannot exceed 480, and the height of the pyramid (the total thickness of the bricks) cannot exceed 360.
4. Define the "Pyramid" building blocks
5. Main function
5.1 Draw a 10-layer pyramid
The effect is as follows: