Vol. 3 Complex Constructions,

4-01-3 Hollow cube

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

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

#  use list and call bar_x, bar_y, bar_z
# 4-01-3 Hollow cube
for j in [10,20]:
    for k in [-20, -10]:
        bar_x(1, j, k, 10, 'cobblestone')

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

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

# 4-01-4 brickCube
# use list and call flat_xy, flat_yz, flat_xz
# 4-01-4 brickCube

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

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

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

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

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)

cube(10,10,-20, 5, 'obsidian' )
hollowCube(20, 10, -20, 8, 'quartz')

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.

Next, let's try put some cubes at pre_selected locations:

tLst = [(0,10,-10), (10,10,-10), (-15, 15,-15), (20,20,-20), (5,40,-20) ]
for i in tLst:
    cube(i[0],i[1],i[2],6,'quartz')
# mark the location coordinate (x,y,z)
for i in tLst:
    block(i[0],i[1],i[2],'wool_blue')

Try put some hollowCubes at some selected locations yourself.

(?? thinking to change m-material number to get colorful cubes. need to rewrite functions: cubeM(flat_M, in turn, bar_M.. back to blockM(x,y,z,m), m is a number for material)

)

def blockM(x,y,z,m):
    game.set_block(Position(x,y,z), m)

for m in range(60, 77):
    blockM((m-60)*5, 10, -20, m)

4-02 Use random()

4-02-1 use randint() in CodeCraft

# 4-02-1
from random import randint

lst = []
for i in range(5):
    lst.append(randint(1,20))
print ( lst)

for i in lst:
    block(i,i, -i,'obsidian')

Run the above application, we will have 5 blocks at random location(in a range), each time we run again, these locations will change.

4-02-2 use randint() directly in CodeCraft

(explain the display of all block materials in Chapter 1, first block)

On top of blockM(), define another set of barM, flatM, then we can get material changing bars, flats, cubes, hollow cubes, that means structures of different colors.

# blockM again
def blockM(x,y,z,m):
    game.set_block(Position(x,y,z), m)

# use integer for m: material
# barM_x
def barM_x(x,y,z,length, m):
    for i in range(x,x+length):
        blockM(i, y, z, material)
# barM_y
def barM_y(x,y,z,length, m):
    for j in range(y,y+length):
        blockM(x, j, z, m)

# barM_z
def barM_z(x,y,z,length, m):
    for k in range(z,z+length):
        blockM(x, y, k, m)

# flatM_xy
def flatM_xy(x,y,z,h,w,m):
    for j in range(y, y+h):
        barM_x(x,j,z,w,m) 
# flatM_yz
def flatM_yz(x,y,z,h,d,m):
    for j in range(y, y+h):
        barM_z(x,j,z,d,m) 
# flatM_xz, (roof)
def flatM_xz(x,y,z,d,w,m):
    for k in range(z, z+d):
        barM_x(x,y,k,w,m)

Can't wait to see a color cube

def cubeM(x,y,z,a,m):
    for k in [z, z+a-1]:
        flatM_xy(x,y,k,a,a,m)
    for j in [y, y+a-1]:
        flatM_xz(x,j,z,a,a,m)
    for i in [x, x+a-1]:
        flatM_yz(i,y,z,a,a,m)

def hollowCubeM(x,y,z,a,m):
    for j in [y,y+a-1]:
        for k in [z, z+a-1]:
            barM_x(x, j, k, a, m)

    for i in [x,x+a-1]:
        for k in [z, z+a-1]:
            barM_y(i, y, k, a, m)
    for j in [y,y+a-1]:
        for i in [x,x+a-1]:
            barM_z(i, j, z, a, m)

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

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

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

(edited to here)

Some Fun Structure
3-14

# useful functions in this app
# 3-03 block(x,y,z,material)

def block(x,y,z,material):
    game.set_block(Position(x,y,z), materials[material])

# 3-08
def Column(x,z,height, material):  
    for j in range(1, height+1):
        block(x,j,z, material)   

# 3-12 Z_line
def Z_line(x,y,z,length, material):
    for k in range(z, (z+length)):
        block(x,y,k, material)

# 3-12-1 roof (loop Z-line)
def roof(x,y,z,width,length,material):
    for i in range(x,(x+width)):
        Z_line(i,y,z,length,material)
# wallX 3-09
def wallX(x,z,h,w,m):
    for i in range(x,(x+w)):
        Column(i,z,h,m)



 #3-14-2 

wallX(0, -21,15,20,'planks_oak')

long zig zag deck

==

(later, for fun proj?)
(Golden Gate Bridge, show picture and put code at the end chapter)

3-06-2 same height columns

for i in range(1, 10,2):
columnC(i,-30, 10, 'red_sandstone')

### 3-07 Fun HiLow columns

```python
# 3-07-1 HiLow columns
def HiLowColA(n):
for i in range(1,2*n,2):
columnC(i, -20, 2*n-i , 'red_sandstone')
columnC(i+2*n, 20, i , 'red_sandstone')
HiLowColA(10)

# 3-07-2 m sets of n HiLow columns
def HiLowColB(n,m):
for i in range(1,2*n,2):
columnC(i+m*40,-15,2*n-i , 'obsidian')
columnC(i+2*n+m*40,-15,i , 'obsidian')
# One set will make the same number of columns as HiLowColA(10), we change z location and material to be black obsidian
HiLowColB(10, 1) # One set will make the same number of columns as HiLowColA(10), we change z location and material to be black obsidian

# Now make 3 sets of HiLow columns:
for t in range(3):
HiLowCol(10,t)

# 3-07-3 GoldenGate
def HiLowColC(n,m,z):
for i in range(1,2*n,3):
columnC(i+m*40,z,2*n-i , 'red_sandstone')
columnC(i+2*n+m*40,z,i , 'red_sandstone')

for t in range(3):
HiLowColC(10,t,-20)
HiLowColC(10,t,-40)

Insert
3-07-4 GoldenGateBridge(with floor board)

# recall 3-07-3 GoldenGate
def HiLowColC(n,m,z):
for i in range(1,2*n,3):
column(i+m*40,z,2*n-i , 'red_sandstone')
column(i+2*n+m*40,z,i , 'red_sandstone')

# 3-07-4 GoldenGateBridge
for t in range(3):
HiLowColC(10,t,-20)
for t in range(3):
HiLowColC(10,t,-40)

# flat_xz(x,y,z,width,length,material)
flat_xz(1,1,-40,20,60,'cobblestone')

===

((A few things- book shelf, flower shelter, ..golden gate,

  • hollow and solid cube(list), colorful cubes(randint, dictionary)

  • photographer's flat

-tree, real tree(randint() ), forest,
))

Application of some Python basic knowledge in CodeCraft

======

Beginning

4-01-3 Hollow cube

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

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

#  use list and call bar_x, bar_y, bar_z
# 4-01-3 Hollow cube
for j in [10,20]:
    for k in [-20, -10]:
        bar_x(1, j, k, 10, 'cobblestone')

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

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

# 4-01-4 brickCube
# use list and call flat_xy, flat_yz, flat_xz
# 4-01-4 brickCube

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

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

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

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

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)

cube(10,10,-20, 5, 'obsidian' )
hollowCube(20, 10, -20, 8, 'quartz')

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.

Next, let's try put some cubes at pre_selected locations:

tLst = [(0,10,-10), (10,10,-10), (-15, 15,-15), (20,20,-20), (5,40,-20) ]
for i in tLst:
    cube(i[0],i[1],i[2],6,'quartz')
# mark the location coordinate (x,y,z)
for i in tLst:
    block(i[0],i[1],i[2],'wool_blue')

Try put some hollowCubes at some selected locations yourself.

(?? thinking to change m-material number to get colorful cubes. need to rewrite functions: cubeM(flat_M, in turn, bar_M.. back to blockM(x,y,z,m), m is a number for material)

)

def blockM(x,y,z,m):
    game.set_block(Position(x,y,z), m)

for m in range(60, 77):
    blockM((m-60)*5, 10, -20, m)

4-02 Use random()

4-02-1 use randint() in CodeCraft

# 4-02-1
from random import randint

lst = []
for i in range(5):
    lst.append(randint(1,20))
print ( lst)

for i in lst:
    block(i,i, -i,'obsidian')

Run the above application, we will have 5 blocks at random location(in a range), each time we run again, these locations will change.

4-02-2 use randint() directly in CodeCraft

(explain the display of all block materials in Chapter 1, first block)

blockM(), m(material) is an integer

Now I will change the parameter material to be a number since materials in game is a dictionary, each different material(dictionary key) is paired with an integer value from 1 to 64.

I will define a new Block() function to accept an integer as material value.

# 4-02-2
from random import randint

# new blockM() function, m:material is an integer
def blockM(x,y,z,m):
    game.set_block(Position(x,y,z), m)

On top of blockM(), define another set of barM, flatM, then we can get material changing bars, flats, cubes, hollow cubes, that means structures of different colors.







# 3-06-2 same height columns

for i in range\(1, 10,2\):  
columnC\(i,-30, 10, 'red\_sandstone'\)

    ### 3-07 Fun HiLow columns

    ```python
    # 3-07-1 HiLow columns
    def HiLowColA(n):
    for i in range(1,2*n,2):
    columnC(i, -20, 2*n-i , 'red_sandstone')
    columnC(i+2*n, 20, i , 'red_sandstone')
    HiLowColA(10)

    # 3-07-2 m sets of n HiLow columns
    def HiLowColB(n,m):
    for i in range(1,2*n,2):
    columnC(i+m*40,-15,2*n-i , 'obsidian')
    columnC(i+2*n+m*40,-15,i , 'obsidian')
    # One set will make the same number of columns as HiLowColA(10), we change z location and material to be black obsidian
    HiLowColB(10, 1) # One set will make the same number of columns as HiLowColA(10), we change z location and material to be black obsidian

    # Now make 3 sets of HiLow columns:
    for t in range(3):
    HiLowCol(10,t)

    # 3-07-3 GoldenGate
    def HiLowColC(n,m,z):
    for i in range(1,2*n,3):
    columnC(i+m*40,z,2*n-i , 'red_sandstone')
    columnC(i+2*n+m*40,z,i , 'red_sandstone')

    for t in range(3):
    HiLowColC(10,t,-20)
    HiLowColC(10,t,-40)

**Insert**  
**3-07-4 GoldenGateBridge\(with floor board\)**

```python
# recall 3-07-3 GoldenGate
def HiLowColC(n,m,z):
for i in range(1,2*n,3):
column(i+m*40,z,2*n-i , 'red_sandstone')
column(i+2*n+m*40,z,i , 'red_sandstone')

# 3-07-4 GoldenGateBridge
for t in range(3):
HiLowColC(10,t,-20)
for t in range(3):
HiLowColC(10,t,-40)

# flat_xz(x,y,z,width,length,material)
flat_xz(1,1,-40,20,60,'cobblestone')

===

results matching ""

    No results matching ""