Example #1
0
    def populate(self, chunk, seed):
        """
        Make smooth waves of stone.
        """

        sede = seed ^ 0xcafebabe
        xzfactor = 1 / 128
        yfactor = 1 / 64

        for x, z in XZ:
            magx = (chunk.x * 16 + x) * xzfactor
            magz = (chunk.z * 16 + z) * xzfactor

            for y in range(CHUNK_HEIGHT):
                if not chunk.get_block((x, y, z)):
                    continue

                magy = y * yfactor

                set_seed(seed)
                should_cave = abs(octaves3(magx, magz, magy, 3))
                set_seed(sede)
                should_cave *= abs(octaves3(magx, magz, magy, 3))

                if should_cave < 0.002:
                    chunk.set_block((x, y, z), blocks["air"].slot)
Example #2
0
    def populate(self, chunk, seed):
        """
        Make smooth waves of stone.
        """

        dees = seed ^ sys.maxint

        # And into one end he plugged the whole of reality as extrapolated
        # from a piece of fairy cake, and into the other end he plugged his
        # wife: so that when he turned it on she saw in one instant the whole
        # infinity of creation and herself in relation to it.

        factor = 1 / 64

        for x, z in product(xrange(16), repeat=2):
            magx = (chunk.x * 16 + x) * factor
            magz = (chunk.z * 16 + z) * factor

            set_seed(seed)
            should_cave = octaves2(magx, magz, 2)

            if should_cave > 0.2:
                set_seed(dees)
                depth = (simplex2(magx, magz) + 1) * 40
                height = depth // 10

                column = chunk.get_column(x, z)
                column[depth:depth + height].fill([blocks["air"].slot])
Example #3
0
    def populate(self, chunk, seed):
        """
        Make smooth waves of stone.
        """

        sede = seed ^ 0xcafebabe
        xzfactor = 1 / 128
        yfactor = 1 / 64

        for x, z in XZ:
            magx = (chunk.x * 16 + x) * xzfactor
            magz = (chunk.z * 16 + z) * xzfactor

            for y in range(CHUNK_HEIGHT):
                if not chunk.get_block((x, y, z)):
                    continue

                magy = y * yfactor

                set_seed(seed)
                should_cave = abs(octaves3(magx, magz, magy, 3))
                set_seed(sede)
                should_cave *= abs(octaves3(magx, magz, magy, 3))

                if should_cave < 0.002:
                    chunk.set_block((x, y, z), blocks["air"].slot)
Example #4
0
    def populate(self, chunk, seed):
        """
        Make smooth waves of stone.
        """

        sede = seed ^ 0xCAFEBABE
        xzfactor = 1 / 128
        yfactor = 1 / 64

        for x, z in product(xrange(16), repeat=2):
            magx = (chunk.x * 16 + x) * xzfactor
            magz = (chunk.z * 16 + z) * xzfactor

            for y in range(128):
                if not chunk.get_block((x, y, z)):
                    continue

                magy = y * yfactor

                set_seed(seed)
                should_cave = abs(octaves3(magx, magz, magy, 3))
                set_seed(sede)
                should_cave *= abs(octaves3(magx, magz, magy, 3))

                if should_cave < 0.002:
                    chunk.set_block((x, y, z), blocks["air"].slot)
Example #5
0
    def populate(self, chunk, seed):
        """
        Make smooth waves of stone.
        """

        set_seed(seed)

        # And into one end he plugged the whole of reality as extrapolated
        # from a piece of fairy cake, and into the other end he plugged his
        # wife: so that when he turned it on she saw in one instant the whole
        # infinity of creation and herself in relation to it.

        factor = 1 / 256

        for x, z in product(xrange(16), repeat=2):
            magx = (chunk.x * 16 + x) * factor
            magz = (chunk.z * 16 + z) * factor

            height = octaves2(magx, magz, 6)
            # Normalize around 70. Normalization is scaled according to a
            # rotated cosine.
            #scale = rotated_cosine(magx, magz, seed, 16 * 10)
            height *= 15
            height = int(height + 70)

            column = chunk.get_column(x, z)
            column[:height + 1].fill([blocks["stone"].slot])
Example #6
0
    def populate(self, chunk, seed):
        """
        Make smooth waves of stone.
        """

        dees = seed ^ sys.maxint

        # And into one end he plugged the whole of reality as extrapolated
        # from a piece of fairy cake, and into the other end he plugged his
        # wife: so that when he turned it on she saw in one instant the whole
        # infinity of creation and herself in relation to it.

        factor = 1 / 64

        for x, z in product(xrange(16), repeat=2):
            magx = (chunk.x * 16 + x) * factor
            magz = (chunk.z * 16 + z) * factor

            set_seed(seed)
            should_cave = octaves2(magx, magz, 2)

            if should_cave > 0.2:
                set_seed(dees)
                depth = (simplex2(magx, magz) + 1) * 40
                height = depth // 10

                column = chunk.get_column(x, z)
                column[depth : depth + height].fill([blocks["air"].slot])
Example #7
0
    def populate(self, chunk, seed):
        """
        Make smooth waves of stone.
        """

        sede = seed ^ 0xcafebabe
        xzfactor = 1 / 128
        yfactor = 1 / 64

        for x, z in product(xrange(16), repeat=2):
            magx = (chunk.x * 16 + x) * xzfactor
            magz = (chunk.z * 16 + z) * xzfactor

            column = chunk.get_column(x, z)

            for y in range(128):
                if not column[y]:
                    continue
                magy = y * yfactor

                set_seed(seed)
                should_cave = abs(octaves3(magx, magz, magy, 3))
                set_seed(sede)
                should_cave *= abs(octaves3(magx, magz, magy, 3))

                if should_cave < 0.002:
                    column[y] = blocks["air"].slot
Example #8
0
    def populate(self, chunk, seed):
        """
        Make smooth waves of stone.
        """

        set_seed(seed)

        # And into one end he plugged the whole of reality as extrapolated
        # from a piece of fairy cake, and into the other end he plugged his
        # wife: so that when he turned it on she saw in one instant the whole
        # infinity of creation and herself in relation to it.

        factor = 1 / 256

        for x, z in product(xrange(16), repeat=2):
            magx = (chunk.x * 16 + x) * factor
            magz = (chunk.z * 16 + z) * factor

            height = octaves2(magx, magz, 6)
            # Normalize around 70. Normalization is scaled according to a
            # rotated cosine.
            #scale = rotated_cosine(magx, magz, seed, 16 * 10)
            height *= 15
            height = int(height + 70)

            column = chunk.get_column(x, z)
            column[:height + 1].fill([blocks["stone"].slot])
Example #9
0
    def populate(self, chunk, seed):
        """
        Make smooth waves of stone.
        """

        set_seed(seed)

        # And into one end he plugged the whole of reality as extrapolated
        # from a piece of fairy cake, and into the other end he plugged his
        # wife: so that when he turned it on she saw in one instant the whole
        # infinity of creation and herself in relation to it.

        factor = 1 / 256

        for x, z in XZ:
            magx = (chunk.x * 16 + x) * factor
            magz = (chunk.z * 16 + z) * factor

            height = octaves2(magx, magz, 6)
            # Normalize around 70. Normalization is scaled according to a
            # rotated cosine.
            #scale = rotated_cosine(magx, magz, seed, 16 * 10)
            height *= 15
            height = int(height + 70)

            # Make our chunk offset, and render into the chunk.
            for y in range(height):
                chunk.set_block((x, y, z), blocks["stone"].slot)
Example #10
0
    def populate(self, chunk, seed):
        """
        Make smooth islands of stone.
        """

        set_seed(seed)

        factor = 1 / 256

        for x, z, y in iterchunk():
            magx = (chunk.x * 16 + x) * factor
            magz = (chunk.z * 16 + z) * factor

            sample = octaves3(magx, magz, y * factor, 6)

            if sample > 0.5:
                chunk.set_block((x, y, z), blocks["stone"].slot)
Example #11
0
    def populate(self, chunk, seed):
        """
        Make smooth islands of stone.
        """

        set_seed(seed)

        factor = 1 / 256

        for x, z, y in iterchunk():
            magx = (chunk.x * 16 + x) * factor
            magz = (chunk.z * 16 + z) * factor

            sample = octaves3(magx, magz, y * factor, 6)

            if sample > 0.5:
                chunk.set_block((x, y, z), blocks["stone"].slot)
Example #12
0
    def populate(self, chunk, seed):
        """
        Make smooth islands of stone.
        """

        set_seed(seed)

        factor = 1 / 256

        for x, z, y in product(xrange(16), xrange(16), xrange(128)):
            magx = (chunk.x * 16 + x) * factor
            magz = (chunk.z * 16 + z) * factor

            sample = octaves3(magx, magz, y * factor, 6)

            if sample > 0.1:
                chunk.set_block((x, y, z), blocks["stone"].slot)
            elif sample > 0:
                chunk.set_block((x, y, z), blocks["dirt"].slot)
Example #13
0
    def populate(self, chunk, seed):
        """
        Make smooth islands of stone.
        """

        set_seed(seed)

        factor = 1 / 256

        for x, z in product(xrange(16), repeat=2):
            column = chunk.get_column(x, z)
            magx = (chunk.x * 16 + x) * factor
            magz = (chunk.z * 16 + z) * factor

            samples = array([octaves3(magx, magz, y * factor, 6) for y in xrange(column.size)])

            column = where(samples > 0, blocks["dirt"].slot, column)
            column = where(samples > 0.1, blocks["stone"].slot, column)

            chunk.set_column(x, z, column)
Example #14
0
    def populate(self, chunk, seed):
        """
        Make smooth waves of stone, then compare to current landscape.
        """

        set_seed(seed)

        factor = 1 / 256
        for x, z in product(xrange(16), repeat=2):
            magx = ((chunk.x + 32) * 16 + x) * factor
            magz = ((chunk.z + 32) * 16 + z) * factor
            height = octaves2(magx, magz, 6)
            height *= 15
            height = int(height + 70)
            current_height = chunk.heightmap[x * 16 + z]
            if -6 < current_height - height < 3 and current_height > 63 and height > 63:
                for y in range(height - 3):
                    chunk.set_block((x, y, z), blocks["stone"].slot)
                for y in range(y, 128):
                    chunk.set_block((x, y, z), blocks["air"].slot)
Example #15
0
    def populate(self, chunk, seed):
        """
        Make smooth waves of stone, then compare to current landscape.
        """

        set_seed(seed)

        factor = 1 / 256
        for x, z in XZ:
            magx = ((chunk.x + 32) * 16 + x) * factor
            magz = ((chunk.z + 32) * 16 + z) * factor
            height = octaves2(magx, magz, 6)
            height *= 15
            height = int(height + 70)
            current_height = chunk.heightmap[x * 16 + z]
            if (-6 < current_height - height < 3 and current_height > 63
                    and height > 63):
                for y in range(height - 3):
                    chunk.set_block((x, y, z), blocks["stone"].slot)
                for y in range(y, CHUNK_HEIGHT // 2):
                    chunk.set_block((x, y, z), blocks["air"].slot)
Example #16
0
    def populate(self, chunk, seed):
        """
        Make smooth islands of stone.
        """

        set_seed(seed)

        factor = 1 / 256

        for x, z in product(xrange(16), repeat=2):
            column = chunk.get_column(x, z)
            magx = (chunk.x * 16 + x) * factor
            magz = (chunk.z * 16 + z) * factor

            samples = array([octaves3(magx, magz, y * factor, 6)
                    for y in xrange(column.size)])

            column = where(samples > 0, blocks["dirt"].slot, column)
            column = where(samples > 0.1, blocks["stone"].slot, column)

            chunk.set_column(x, z, column)
Example #17
0
    def populate(self, chunk, seed):
        set_seed(seed)

        xzfactor = 1 / 16
        yfactor = 1 / 32

        for x, z in product(xrange(16), repeat=2):
            for y in range(chunk.heightmap[x, z] + 1):
                magx = (chunk.x * 16 + x) * xzfactor
                magz = (chunk.z * 16 + z) * xzfactor
                magy = y * yfactor

                sample = octaves3(magx, magz, magy, 3)

                if sample > 0.9999:
                    # Figure out what to place here.
                    old = chunk.blocks[x, z, y]
                    new = None
                    if old == blocks["sand"].slot:
                        # Sand becomes clay.
                        new = blocks["clay"].slot
                    elif old == blocks["dirt"].slot:
                        # Dirt becomes gravel.
                        new = blocks["gravel"].slot
                    elif old == blocks["stone"].slot:
                        # Stone becomes one of the ores.
                        if y < 12:
                            new = blocks["diamond-ore"].slot
                        elif y < 24:
                            new = blocks["gold-ore"].slot
                        elif y < 36:
                            new = blocks["redstone-ore"].slot
                        elif y < 48:
                            new = blocks["iron-ore"].slot
                        else:
                            new = blocks["coal-ore"].slot

                    if new:
                        chunk.blocks[x, z, y] = new
Example #18
0
    def populate(self, chunk, seed):
        set_seed(seed)

        xzfactor = 1 / 16
        yfactor = 1 / 32

        for x, z in product(xrange(16), repeat=2):
            for y in range(chunk.heightmap[x, z] + 1):
                magx = (chunk.x * 16 + x) * xzfactor
                magz = (chunk.z * 16 + z) * xzfactor
                magy = y * yfactor

                sample = octaves3(magx, magz, magy, 3)

                if sample > 0.9999:
                    # Figure out what to place here.
                    old = chunk.blocks[x, z, y]
                    new = None
                    if old == blocks["sand"].slot:
                        # Sand becomes clay.
                        new = blocks["clay"].slot
                    elif old == blocks["dirt"].slot:
                        # Dirt becomes gravel.
                        new = blocks["gravel"].slot
                    elif old == blocks["stone"].slot:
                        # Stone becomes one of the ores.
                        if y < 12:
                            new = blocks["diamond-ore"].slot
                        elif y < 24:
                            new = blocks["gold-ore"].slot
                        elif y < 36:
                            new = blocks["redstone-ore"].slot
                        elif y < 48:
                            new = blocks["iron-ore"].slot
                        else:
                            new = blocks["coal-ore"].slot

                    if new:
                        chunk.blocks[x, z, y] = new
Example #19
0
                  help="Random seed to use",
                  type="int",
                  default=0)
parser.add_option("-f",
                  "--offset",
                  help="Difference offset",
                  type="str",
                  default="")

options, arguments = parser.parse_args()

xoffset, yoffset = 0, 0
if options.offset:
    xoffset, yoffset = (float(i) for i in options.offset.split(","))

set_seed(options.seed)

x, y, w, h = (float(i) for i in arguments)

image = Image.new("L", (WIDTH, HEIGHT))
pbo = image.load()

counts = [1, 2, 4, 5, 8]
count = 0
total = WIDTH * HEIGHT

print "Seed: %d" % options.seed
print "Coords: %f, %f" % (x, y)
print "Window: %fx%f" % (w, h)
print "Octaves: %d" % options.octaves
print "Offsets: %f, %f" % (xoffset, yoffset)
Example #20
0
#!/usr/bin/env python

from __future__ import division

import random

from bravo.simplex import set_seed, octaves2

ITERATIONS = 10 * 1000 * 1000

set_seed(0)

for octave in range(1, 6):
    print "Testing octave", octave
    minimum, maximum = 0, 0

    for i in xrange(ITERATIONS):
        x = random.random()
        y = random.random()
        sample = octaves2(x, y, octave)
        if sample < minimum:
            minimum = sample
            print "New minimum", minimum
        elif sample > maximum:
            maximum = sample
            print "New maximum", maximum

    print "Champs for octave", octave, minimum, maximum
Example #21
0
#!/usr/bin/env python

from functools import wraps
from time import time

from bravo.simplex import set_seed, simplex2, simplex3, octaves2, octaves3

print "Be patient; this benchmark takes a minute or so to run each test."

chunk2d = 16 * 16
chunk3d = chunk2d * 128

set_seed(time())

def timed(f):
    @wraps(f)
    def deco():
        before = time()
        for i in range(1000000):
            f(i)
        after = time()
        t = after - before
        actual = t / 1000
        print ("Time taken for %s: %f seconds" % (f, t))
        print ("Time for one call: %d ms" % (actual))
        print ("Time to fill a chunk by column: %d ms"
            % (chunk2d * actual))
        print ("Time to fill a chunk by block: %d ms"
            % (chunk3d * actual))
        print ("Time to fill 315 chunks by column: %d ms"
            % (315 * chunk2d * actual))
Example #22
0
 def setUp(self):
     set_seed(0)
Example #23
0
 def setUp(self):
     set_seed(0)
Example #24
0
#!/usr/bin/env python

from time import time

from bravo.simplex import set_seed, simplex2, simplex3

set_seed(time())


def bench2():
    times = []
    for i in range(25):
        before = time()
        for i in range(10000):
            simplex2(i, i)
        after = time()
        t = (after - before) / 10000
        times.append(1 / t)
    return "simplex2", times


def bench3():
    times = []
    for i in range(25):
        before = time()
        for i in range(10000):
            simplex3(i, i, i)
        after = time()
        t = (after - before) / 10000
        times.append(1 / t)
    return "simplex3", times
Example #25
0
parser = optparse.OptionParser()
parser.add_option("-o", "--octaves", help="Number of octaves to generate",
    type="int", default=1)
parser.add_option("-s", "--seed", help="Random seed to use", type="int",
    default=0)
parser.add_option("-f", "--offset", help="Difference offset", type="str",
default="")

options, arguments = parser.parse_args()

xoffset, yoffset = 0, 0
if options.offset:
    xoffset, yoffset = (float(i) for i in options.offset.split(","))

set_seed(options.seed)

x, y, w, h = (float(i) for i in arguments)

image = Image.new("L", (WIDTH, HEIGHT))
pbo = image.load()

counts = [1, 2, 4, 5, 8]
count = 0
total = WIDTH * HEIGHT

print "Seed: %d" % options.seed
print "Coords: %f, %f" % (x, y)
print "Window: %fx%f" % (w, h)
print "Octaves: %d" % options.octaves
print "Offsets: %f, %f" % (xoffset, yoffset)