16 - Structures with for
loops
Let's build a few big structures using for
loops. I have some examples shown in the pictures below. You can save some effort to make these by calling the functions we have defined previously. At the end of this chapter you will find sample code to build these structures.
16-01 Stairs (simple for
loop)
16-02 Blue and Red Dots (nested loops)
16-03 Pyramid (call flat_xz()
)
16-04 Building
Using lists
Lists are useful for storing some locations. Use lists to store x, z
values for some columns and build a shelter:
# shelter
for i in [0, 14]:
for k in [-10, -5]:
column(i, k, 10, 'obsidian')
flat_xz(0, 10, -10, 15, 6, 'diamond')
Can you try building a shelf like the one below?
16-05 Book shelf
16-06 Rainbow
Lists are also useful for storing material names. We can select some colorful blocks and put them in a list:
# List of rainbow blocks
rainbow_colors = ['linen_red', 'linen_orange', 'linen_yellow', 'linen_green', 'linen_cyan', 'linen_blue', 'linen_purple']
Then we can loop through this rainbow_colors
list and build a few rows of blocks: