Quilt

color_quilt

Fit two butterflies together, we get a color quilt:

# quilt, color square
def quilt(x, y, z, d, m):
    for i in range(-d, d+1):
        block(x+i, y+d, z, m)
        block(x+i, y-d, z, m)
    for j in range(-d, d+1):
        block(x-d, y+j, z, m)
        block(x+d, y+j, z, m)

    if d < 10:
        game.set_timer(1, quilt, x, y, z, d+1, m+1)

quilt(-30, 20, -40, 0, 48)

Quilt Rotation

Split Quilt

Thoughtfully manipulate loops and timer function arguments, we can produce amazing structures in CodeCraft.

Based on quilt(), there are 4 lines of block() under for loops. We change z to be z+i or z+j one by one, so we can see how these argument values affect the structure.

def quiltUp(x,y,z,d,m):
    for i in range(-d, d+1):
        block(x+i, y+d, z+i, m)     # updated z
        block(x+i, y-d, z, m)
    for j in range(-d, d+1):
        block(x-d, y+j, z, m)
        block(x+d, y+j, z, m)

    if d < 10:
        game.set_timer(1, quiltUp, x, y, z, d+1, m+1)

quiltUp(0, 40,-40,0, 48)

def quiltLeft(x,y,z,d,m):
  for i in range(-d, d+1):
    block(x+i, y+d, z, m) 
    block(x+i, y-d, z, m)
  for j in range(-d, d+1):
    block(x-d, y+j, z+j, m)    # updated z
    block(x+d, y+j, z, m)
  if d<10:
    game.set_timer(1, quiltLeft, x, y, z, d+1, m+1)

quiltLeft(0, 12, -40, 0, 48)

We can replace z in each line one by one, to check how this argument affect the shapes in quiltUp and quiltLeft.

Would you define quiltRight and quiltDown yourself?

Reference code:

def quiltDown(x,y,z,d,m):
  for i in range(-d, d+1):
    block(x+i, y+d, z, m)
    block(x+i, y-d, z+i, m)       # updated z
  for j in range(-d, d+1):
    block(x-d, y+j, z, m) 
    block(x+d, y+j, z, m)
  if d<10:
    game.set_timer(1, quiltDown, x, y, z, d+1, m+1)

quiltDown(30, 40,-40,0, 48)

def quiltRight(x,y,z,d,m):
  for i in range(-d, d+1):
    block(x+i, y+d, z, m)
    block(x+i, y-d, z, m)       
  for j in range(-d, d+1):
    block(x-d, y+j, z, m) 
    block(x+d, y+j, z+j, m)    # updated z
  if d<10:
    game.set_timer(1, quiltRight, x, y, z, d+1, m+1)

quiltRight(30, 12,-40,0, 48)

I'm sure you like to try this one yourself:

quiltSplit

results matching ""

    No results matching ""