Application in CodeCraft

list is useful in CodeCraft to store location coordinates

List is useful in CodeCraft to put structures at pre-decided various locations.

Some columns at various x locations

# two ways to loop through a list
x_lst = [3,18, -10, -2, 14, 20]

for item in x_lst:
    column(item, -20, 15, 'dirt')

for i in range(len(x_lst)):
    column(x_lst[i], -20, 10, 'obsidian')

The above example show that two ways of looping through list do the same thing. The first for loop build some dirt columns of height 15; the second for loop build some obsidian columns of height 10 at the same locations; So you will see the columns have two color.

Some blocks at pre-selected locations

list of lists

Use list to store the point coordinates and the material number: [x,y,z,m]

lst = [ [2,4,-9, 73], [2,2,-9,73], [3,3,-10,76], [4,2,-9,73], [4,4,-9,73] ] 

for i in range(len(lst)):
    block(lst[i][0], lst[i][1], lst[i][2], lst[i][3])

Note: lst is a list consists of 4 number lists, lst[2][0] means the first number(index 0) in the third item (lst[2])

=====

(extra? in Ch.5, complex structures)

(use list of tuples, ) List of tuples representing some selected location coordinates (x,y,z)

4-01-2 Some blocks in the air

# 4-01-2
# us a tuple list to store the locations (x,y,z)
lst = [(2,8,-10),(5,15,-15),(12,3,-20),(16,10, -10)]

# put a bar_z at the first tuple indicated location (2,8,-10)
bar_z(lst[0][0], lst[0][1], lst[0][2], 5, 'dirt')

for i in lst:
    block(i[0],i[1],i[2],10,'quartz')

We can use list of tuples to store some location coordinates (x,y,z), then build some structures at these selected locations, the above app just put some blocks.

results matching ""

    No results matching ""