Matrix / Array ??

x * y block array

def matrix2D(x,y,z,m,d):
    blocks_x(x,y,z,m,d)

    if y<30:
        game.set_timer(0.5, matrix2D, x, y+d, z, m, d)

matrix2D(0,1,-20,'brick', 10)

Another version of 2D matrix, use for loop instead of another timer.

matrix2d

# another version of matrix2D

def matrix2d(x,y,z,m,d):
    for j in range(int(20/d)+1):
        blocks_x(x, (y+j*d), z,m,d)

matrix2d(0,2,-40,'quartz',4)

3D matrix

def matrix3D(x,y,z,m,d):
    block_matrix(x,y,z,m,d)

    if z<0:
        game.set_timer(0.2,matrix3D, x,y,z+d,m,d)

matrix3D(0,1,-40,'obsidian',10)

matrix3D will build a 3D block matrix within a xyz range defined inside the function, right now it's x,y<30; z<0.

(blocks_x, blocks_y, blocks_z,blocks_xy,blocks_xyz matrix2D matrix3D )

Array?? N

blocks_xN matrix2DN matrix3DN I'm thinking if we can use input argument to build a specific number of blocks instead of within a range defined inside the function.

Recall that block_x(x,y,z,m,d) will build blocks along x in range (x<60). If we want to build more or less blocks, we need to change the terminating condition inside recursive function considering the step d, and the starting and ending locations.

Let's try adding a input argument n (the number of blocks to build) to the function and change the terminating condition accordingly, so we can build n(input argument) blocks:

blocks_xN(x,y,z,m,d,n)

# for reference
# blocks_x
def blocks_x(x,y,z,m,d): 
    block(x,y,z,m)
    if x<60:         #terminating condition 
        game.set_timer(1,blocks_x, x+d,y,z,m,d)

# blocks_xN ( n blocks along x, step d)
def blocks_xN(x,y,z,m,d,n):
    block(x,y,z,m)
    if x<((n-1)*d):    # depends on n 
        game.set_timer(0.5, blocks_xN, x+d, y,z,m,d,n)

blocks_xN(0,1,-40,'brick',10, 3)
blocks_xN(0,2,-40,'obsidian',5, 6)

The above blocks_xN() will take a number n as input argument and build n blocks along x with step d.

Attention, the starting location x needs to be, x<d to make enough blocks.

Def blockSheet(x,y,z,m,d,n): for j in range(n+1): blocks_xN(x,y+n*d,z,m,d,n)

Based on blocks_xN(), we can build a n*n block matrix in 2D x-y plane:

matrix2D

def matrix2DN(x,y,z,m,d,n):
    blocks_xN(x,y,z,m,d,n)
    if y < (n-1)*d:
        game.set_timer(0.5, matrix2DN, x,y+d,z,m,d,n)
matrix2DN(0,1,-20,'wool_red',3,10)

Have some fun with matrix2DN:

for k in range(5):
    matrix2DN(0,1, (-30+5*k), 'wool_blue', 3, k)


for k in range(5):
    matrix2DN(0,1, (-30+5*k), 'wool_blue', 3, 5)

We can make 3D matrix that's nnn:

def matrix3DN(x,y,z,m,d,n):
    for k in range(n):
        matrix2DN(x,y,z+d*k,m,d,n)    


matrix3DN(0,1,-40,'obsidian',10)

=== (??? x,y initial value must <d, otherwise make less blocks, how to change, how to get x0, so y<((n-1)*d+x0)

results matching ""

    No results matching ""