Bars and Flats

More Application of for loop and the basic functions

The functions, block() and column(), are the most basic in CodeCraft, let's see the application of them with for loops to build some simple structures.

Use block(x,y,z,m)

Example 1: 3 lines of cobblestone blocks (along x,y,z directions)

for i in range(10):
    block(i,1, -20, 2)      # loop through x
    block(0, i, -20, 2)     # loop through y
    block(0,1, i-20, 2)     # loop through z

Example 2: separated blocks, along x, xy, xyz

# loop x, yellow
for i in range(1, 20, 2):
    block(i,10, -20, 76')

# loop xy, blue
for i in range(1, 20, 2):
    block(i, i, -20, 62)

# loop x,y,z, red
for i in range(1, 20, 2):
    block(i, i, -i, 73)

# add two y lines for reference
for j in range(1, 20, 2):
    block(0, j, -1, 'obsidian')
for j in range(1, 20, 2):
    block(19, j, -20, 'obsidian')

Example 3:

Using nesting loops we can make an array of blocks:

for i in range(1,10,2):
    for k in range(-20, -10, 2):
        block(i, 5, k, 'shulker_lime')

Use column(x,z,h,m)

Similar to block, put column and for loops together we can have, of cause, many columns:

Example 1: A line of columns along x axis, every 5 blocks

for i in range(0, 30, 5):
    column(i, -21, 10, 2)       # cobblestone

Example 2: Putting columns of any material anywhere is just a breeze.

# 3 rows of columns
for i in range(1, 10, 2):
    column(i,-10, 5, 1)      # brick
    column(i, -12, 5+i, 3)   # diamond    

    column(i, -20, 10, 4)    # dirt

# 3rows Variation
for i in range(1, 10, 2):
    column(i,-10, 10, 'cobblestone')
    column(i+10, -10+i, 10, 'brick')
    column(-i, -10+i, 10, 'dirt')

Define functions to build bars and flats

We are not at stone age, just using blocks and columns is not good enough to construct things. We have Home Depot, many beams and boards to choose from.

Let's expand our inventory, define functions to build bars and flats to use repeatedly in later programs.

# bar_x
def bar_x(x,y,z,length, m):
    for i in range(x,x+length):
        block(i, y, z, m)
# bar_y
def bar_y(x,y,z,length, m):
    for j in range(y,y+length):
        block(x, j, z, m)
# bar_z
def bar_z(x,y,z,length, m):
    for k in range(z,z+length):
        block(x, y, k, m)

# flat_xy
def flat_xy(x,y,z,h,w,m):
    for j in range(y, y+h):
        bar_x(x,j,z,w,m) 
# flat_yz
def flat_yz(x,y,z,h,d,m):
    for j in range(y, y+h):
        bar_z(x,j,z,d,m) 
# flat_xz, (roof)
def flat_xz(x,y,z,d,w,m):
    for k in range(z, z+d):
        bar_x(x,y,k,w,m) 

# wall
def wall(x,z,h,w,m):
    for i in range(x,(x+w)):
        column(i,z,h,m)

# sideWall
def sideWall(x,z,h,w,m):
    for k in range(z,z+w):
        column(x,k,h,m)

Demo the above functions:

# bars
bar_x(


# flats

results matching ""

    No results matching ""