Cubes, Colorful Cubes

4-01-3 Hollow cube

(???define functions for cubes, then use above tuple list)

Practice some Gemeotry knowledge, make a brick cube and a hollow cube using the flat and bar functions together with list.

Use list and call flat_xy, flat_yz, flat_xz to build a brick cube:

# brick cube

for k in[-20, -11]:
    flat_xy(20,10,k,10,10, 1)

for j in[10, 19]:
    flat_xz(20,j,-20,10,10, 1)

for i in[20, 29]:
    flat_yz(i,10,-20,10,10, 1)

Use list and call bar_x, bar_y, bar_z to build a hollow cube

# Hollow cube, cobblestone
for j in [10,20]:
    for k in [-20, -10]:
        bar_x(1, j, k, 10, 2)

for i in [1,10]:
    for k in [-20, -10]:
        bar_y(i, 10, k, 10, 2)

for j in [10,20]:
    for i in [1,10]:
        bar_z(i, j, -20, 10, 2)

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

One corner is at (x,y,z), side length a, material number 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)

def hollowCube(x,y,z,a,m):
    for j in [y,y+a-1]:
        for k in [z, z+a-1]:
            bar_x(x, j, k, a, m)
    for i in [x,x+a-1]:
        for k in [z, z+a-1]:
            bar_y(i, y, k, a, m)
    for j in [y,y+a-1]:
        for i in [x,x+a-1]:
            bar_z(i, j, z, a, m)

Let's call to build a black cube and a white hollow cube:


cube(10,10,-20, 5, 27 )
hollowCube(20, 10, -20, 8, 35)

Some colorful cubes and hollow cubes, looping through the material number m to build cubes with varying color.

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

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

pic, cubes

Things are getting fancier! (show pics, maybe the code put in last Chapter)

results matching ""

    No results matching ""