Ejemplo n.º 1
0
def initialise(plane, chance, material):
    # Randomly seed the plane
    print "Initialising..."
    count = 0
    for x in xrange(0, plane.Width):
        for y in xrange(0, plane.Height):
            if random() <= chance:
                setBlock(plane, x, y, 0, material)
                count += 1
    print "Initialised", count, "blocks!"
Ejemplo n.º 2
0
def calculateLifeTick(prevPlane, plane, material):
    DEAD = -1
    ALIVE = 1
    AIR = 0, 0

    Q = zeros(
        (plane.Width, plane.Height)
    )  # -1 = dead, otherwise the number indicates the number of neighbours

    countAlive = 0
    countDeath = 0
    countBirth = 0
    # Seed the field with the blocks from the MCEdit selection
    for iterY in xrange(0, plane.Height):
        for iterX in xrange(
                0, plane.Width):  # For each cell in the previous plane
            if prevPlane.blockAt(iterX, iterY, 0) != 0:  # Not air
                Q[iterX, iterY] = ALIVE  # alive
            else:
                Q[iterX, iterY] = DEAD
    logMessage("calculateLifeTick", "Sweeping plane")
    for iterY in xrange(0, plane.Height):
        for iterX in xrange(
                0, plane.Width):  # For each cell in the previous plane
            neighbourCount = 0
            for ix in xrange(-1, 2):
                for iy in xrange(-1, 2):
                    if ix == 0 and iy == 0:
                        t = 0  # Pass
                    else:  #if ix != 0 or iz != 0: # Don't count the current cell
                        if iterX + ix < plane.Width and iterX + ix >= 0 and iterY + iy < plane.Height and iterY + iy >= 0:  # Only consider cells in the plane, no loops
                            if Q[iterX + ix, iterY + iy] != DEAD:
                                neighbourCount = neighbourCount + 1
            if Q[iterX, iterY] != DEAD:  # It's alive!
                if neighbourCount < 2 or neighbourCount > 3:  # Lonely or crowded, die in the next generation
                    # setBlock(plane,AIR,iterX,iterY) # DEAD
                    #print 'killing %s %s' % (iterX, iterZ)
                    countDeath = countDeath + 1
                elif neighbourCount == 2 or neighbourCount == 3:  # Live another day
                    setBlock(plane, iterX, iterY, 0, material)  # Alive
                    # print 'leaving alive %s %s' % (iterX, iterZ)
                    countAlive = countAlive + 1
            else:  # It is dead
                if neighbourCount == 3:
                    setBlock(plane, iterX, iterY, 0,
                             material)  # Alive! Born again.
                    # print 'new baby at %s %s' % (iterX, iterZ)
                    countBirth = countBirth + 1
                else:
                    t = 0  # Pass. Q[iterX, iterY, 0] = DEAD # Set it dead on the target field.
    print "This tick: Alive", countAlive, "Born", countBirth, "Died", countDeath
    logMessage("calculateLifeTick", "Plane swept")
Ejemplo n.º 3
0
def hemisphere(level, box, options):
    ''' Plot all the pixels to the surface above the selection, which is a hemisphere
		The lowest layer of the selection is the selection of blocks to be translated into the hemisphere
	'''
    fraction = options["Fraction of sphere to render"]
    radius = float(box.maxy - box.miny
                   ) * fraction * 2.0  # This is the radius of the hemisphere
    cx = (box.minx + box.maxx) >> 1  # Mid point along width of selection
    cz = (box.minz + box.maxz) >> 1  # Mid point along depth of selection

    # Traverse each layer of the selection
    # If the voxel is in the surface of the hemisphere, find what block it should be

    y = box.maxy - 1
    halfcirc = pi * radius
    while y > box.miny:
        if y % 10 == 0: print y
        for x in xrange(box.minx, box.maxx):
            for z in xrange(box.minz, box.maxz):
                dx = x - cx
                dz = z - cz
                dy = y - box.miny
                hdistsq = dx**2 + dz**2
                if int(radius) == int(sqrt(hdistsq + dy**2)):
                    # This block position is on the hemisphere
                    # Calculate the distance from the top of the dome around the circumference (longitudinal) and the angle (latitude)

                    # 2*pi*r = pi*d = circumference

                    hangle = atan2(dz, dx)
                    vangle = atan2(dy, sqrt(hdistsq))
                    distratio = (pi / 2 - vangle) / (fraction * 2.0 * pi)
                    dist = distratio * halfcirc
                    #print dist
                    # Lookup the block that is at the appropriate angle and distance in the lowest layer
                    theBlock = getBlock(level, cx + dist * cos(hangle),
                                        box.miny, cz + dist * sin(hangle))
                    setBlock(level, x, y, z, theBlock)

        y -= 1  # Move down one layer

    print "Done!"
Ejemplo n.º 4
0
def rotateslice(level, box, options):
    ''' Given a width-wise selection, rotate it 360
	'''

    width = (box.maxx - box.minx) << 1
    height = (box.maxy - box.miny)
    depth = width

    for y in xrange(box.miny, box.maxy):  # Scan the target space
        if y % 10: print y
        for z in xrange(box.maxz, box.minz +
                        (width >> 1)):  # Start one step out from the selection
            for x in xrange(box.minx, box.maxx):
                #				if x < box.minx or z != box.minz: # Don't try to map over the source blocks
                dx = x - box.minx  # distance from centre
                dz = z - box.minz

                rHere = sqrt(dx**2 + dz**2)

                # Find the block that needs to be mapped in here
                theBlock = getBlock(level, box.minx + int(rHere), y, box.minz)
                if theBlock != (0, 0):
                    setBlock(level, x, y, z, theBlock)  # Quadrant1
                    setBlock(level, box.minx - dx, y, z, theBlock)  # Quadrant2
                    setBlock(level, x, y, box.minz - dz, theBlock)  # Quadrant3
                    setBlock(level, box.minx - dx, y, box.minz - dz,
                             theBlock)  # Quadrant4
        z = box.minz
        for x in xrange(box.minx, box.maxx):
            theBlock = getBlock(level, x, y, z)
            if theBlock != (0, 0):
                setBlock(level, box.minx - (x - box.minx), y, z,
                         theBlock)  # Quadrant1

    level.markDirtyBox(
        BoundingBox(
            (box.minx - (width >> 1), box.miny, box.minz - (width >> 1)),
            (width, height, width)))
    print "Done!"
Ejemplo n.º 5
0
    width = img.size[0]
    height = img.size[1]

    # Put the image in the centre of the plane

    gapWidth = (plane.Width - width) >> 1
    gapHeight = (plane.Height - height) >> 1
    print width, height
    for x in xrange(0, width):
        for y in xrange(0, height):
            (r, g, b, a) = imgPix[x, y]
            if r == R and g == G and b == B:
                px = x + gapWidth
                py = y + gapHeight
                if px >= 0 and px < plane.Width and py >= 0 and py < plane.Height:  # Bounds check
                    setBlock(plane, px, py, 0, material)
    logMessage("loadImageFromFile", "End")


def initialise(plane, chance, material):
    # Randomly seed the plane
    print "Initialising..."
    count = 0
    for x in xrange(0, plane.Width):
        for y in xrange(0, plane.Height):
            if random() <= chance:
                setBlock(plane, x, y, 0, material)
                count += 1
    print "Initialised", count, "blocks!"