Reference Code

The structures we created in this chapter, for you to use as reference.

16-01 Stairs (simple for loop)

for i in range(1, 60, 2):
  flat_xz(i, i, -10, 6, 3, 'cobblestone')

16-02 Blue Dots Red Dots (nesting loops)

game.clear_screen() 

for j in range(0,10,2):
  block(0, j+1, -20, 'box_black')

for j in range(0,10,2):
  for i in range (-j, j+1, 2):
    block(i-10, j+1, -20, 'linen_blue')

for j in range(0,10,3):
  for i in range (-j, j+1, 3):
    for k in range(-j, j+1, 3):
      block(i+10, j+1, k-20, 'linen_red')

16-03 Pyramid (call flat_xz())

for i in range(10):
    flat_xz(i, i, -20+i, 20-2*i, 20-2*i, 'brick')

16-04 Building

for i in range(20, 30):
    for j in range(1, 12, 2):
        for k in range(-20, -10, 2):
            block(i, j, k, 'cobblestone')
            block(i, j+1, k, 'diamond')

16-05 Book Shelf

# book shelf
for i in [0, 14]:
    for k in [-10, -5]:
        column(i, k, 40, 'obsidian')

for j in range(10, 40, 5):        
    flat_xz(0, j, -10, 15, 6, 'diamond')

16-06 Rainbow

for i in range(len(rainbow_colors)):
  color = rainbow_colors[i]
  bar_x(0, 20+i, -30, 60, color)

Death Star

16-07 Big Circle

# big circle, green, radius 20
for i in range(-20, 21):
  for j in range(-20, 21):
    if i*i + j*j <= 400:
      block(i+35, j+25, -20, 'linen_lime')

16-08 Function circle()
circle(x,y,z,r,m)**, r is the radius, m is the material.

def circle(x, y, z, r, m):
  for i in range(-r, r+1):
    for j in range(-r, r+1):
      if i*i+j*j <= r*r:
        block(i+x, j+y, z, m)

# many circles
circle(0, 20, -10, 8, 'linen_pink') 
circle(5, 30, -10, 10, 'linen_purple')
circle(-5, 30, 0, 15, 'ice')
circle(20, 10, 10, 10, 'glass_orange')

16-09 A Sphere Function

def sphere(x, y, z, m):
  for i in range(-10, 11):
    for j in range(-10, 11):
      for k in range(-10, 11):
        if i*i + j*j + k*k <= 100:
          block(i+x, j+y, k+z, m)

results matching ""

    No results matching ""