def populate(self, chunk, seed): """ Make smooth waves of stone. """ reseed(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])
def populate(self, chunk, seed): """ Make smooth islands of stone. """ reseed(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)
def populate(self, chunk, seed): reseed(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.get_block((x, y, z)) if old == blocks["sand"].slot: # Sand becomes clay. chunk.set_block((x, y, z), blocks["clay"].slot) elif old == blocks["dirt"].slot: # Dirt becomes gravel. chunk.set_block((x, y, z), blocks["gravel"].slot) elif old == blocks["stone"].slot: # Stone becomes one of the ores. if y < 12: chunk.set_block((x, y, z), blocks["diamond-ore"].slot) elif y < 24: chunk.set_block((x, y, z), blocks["gold-ore"].slot) elif y < 36: chunk.set_block((x, y, z), blocks["redstone-ore"].slot) elif y < 48: chunk.set_block((x, y, z), blocks["iron-ore"].slot) else: chunk.set_block((x, y, z), blocks["coal-ore"].slot)
def populate(self, chunk, seed): reseed(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
def populate(self, chunk, seed): """ Make smooth islands of stone. """ reseed(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)
#!/usr/bin/env python from functools import wraps from time import time from bravo.simplex import reseed, simplex2, simplex3, octaves2, octaves3 print "Be patient; this benchmark takes a minute or so to run each test." chunk2d = 16 * 16 chunk3d = chunk2d * 128 reseed(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)) print("Time to fill 315 chunks by block: %d ms" %
def setUp(self): reseed(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(",")) reseed(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)
#!/usr/bin/env python from time import time from bravo.simplex import reseed, simplex2, simplex3 reseed(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 benchmarks = [bench2, bench3]
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(",")) reseed(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)