Cubes, Colorful Cubes

With some geometry concepts, let's design a solid cube and a hollow cube using the flat() and bar() functions together with list.

Use a list to store the coordinates, and call flat_xy, flat_yz, flat_xz to build the six sides of a brick cube. Here are the top and bottom sides:

# top and bottom sides
for j in[10, 19]:
    flat_xz(20, j, -20, 10, 10, 'brick')

17-01 Cube

Try to finish other sides of the cube and make it look like the brick cube in the picture:

17-02 Hollow Cube

Use a list and call bar_x, bar_y, bar_z to build a hollow cube like the gray one showed in the above picture.

Functions for cube and hollowCube

Let's define functions for cube and hollow cube, so we can build these structures at any location with any material.

Function cube(x,y,z,a,m): one corner is at (x,y,z), with side length a and material m

def cube(x,y,z,a,m):
    for k in [z, z+a-1]:
        flat_xy(x,y,k,a,a,m)
    for j in [y, y+a-1]:
        flat_xz(x,j,z,a,a,m)
    for i in [x, x+a-1]:
        flat_yz(i,y,z,a,a,m)

17-03 Function hollow_cube(x,y,z,a,m)

Try defining function hollow_cube() yourself!

Let's call these two functions to build a cube inside a hollow cube:

cube(10, 10, -20, 5, 'box_blue' )
hollow_cube(6, 6, -20, 10, 'glass_green')

Use material numbers

Next, go back to the top of the program, comment out block() which uses m as material name string, then insert another block() that uses m as material number. Keep all other functions in place. Now all the flats, bars and cube, hollowCube are using m as the material number.

# another block function
def block(x,y,z,m):
    game.set_block(Position(x,y,z), m)

Let's loop through the material number m to build cubes with varying color.

I chose the "linen" blocks from number 49 to 59:

# let's see some colorful cubes:
for m in range(49, 60):
    cube((m-49)*5, 20,-20, 3, m)

# and some colorful hollowCubes
for m in range(49, 60):
    hollowCube(0, (m-49)*5, -20, 3, m)

Things are getting fancier!

results matching ""

    No results matching ""