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])
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)
def populate(self, chunk, seed): """ Create floating islands. """ # Eat moar stone R.seed(seed) factor = 1 / 256 for x, z in XZ: magx = ((chunk.x + 16) * 16 + x) * factor magz = ((chunk.z + 16) * 16 + z) * factor height = octaves2(magx, magz, 6) height *= 15 height = int(height + 70) if abs(chunk.heightmap[x * 16 + z] - height) < 10: height = CHUNK_HEIGHT else: height = height - 30 + R.randint(-15, 10) for y in range(height): chunk.set_block((x, y, z), blocks["air"].slot)
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])
def populate(self, chunk, seed): """ Create floating islands. """ # Eat moar stone R.seed(seed) factor = 1 / 256 for x, z in XZ: magx = ((chunk.x+16) * 16 + x) * factor magz = ((chunk.z+16) * 16 + z) * factor height = octaves2(magx, magz, 6) height *= 15 height = int(height + 70) if abs(chunk.heightmap[x * 16 + z] - height) < 10: height = CHUNK_HEIGHT else: height = height - 30 + R.randint(-15, 10) for y in range(height): chunk.set_block((x, y, z), blocks["air"].slot)
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])
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 waves of stone, then compare to current landscape """ 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) if -6 < chunk.heightmap[x, z] - height < 3 and chunk.heightmap[x, z] > 63 and height > 63: column = chunk.get_column(x, z) column.fill(blocks["air"].slot) column[: height - 3].fill(blocks["stone"].slot)
def populate(self, chunk, seed): """ Make smooth waves of stone, then compare to current landscape """ 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) if (-6 < chunk.heightmap[x, z] - height < 3 and chunk.heightmap[x, z] > 63 and height > 63): column = chunk.get_column(x, z) column.fill(blocks["air"].slot) column[:height-3].fill(blocks["stone"].slot)
def populate(self, chunk, seed): """ Eat moar stone """ factor = 1 / 256 for x, z in product(xrange(16), repeat=2): magx = ((chunk.x+16) * 16 + x) * factor magz = ((chunk.z+16) * 16 + z) * factor height = octaves2(magx, magz, 6) height *= 15 height = int(height + 70) column = chunk.get_column(x, z) if abs(chunk.heightmap[x,z] - height) < 10: column[:].fill(blocks["air"].slot) else: column[:height-30+randint(-15,10)].fill(blocks["air"].slot)
def populate(self, chunk, seed): """ Eat moar stone """ factor = 1 / 256 for x, z in product(xrange(16), repeat=2): magx = ((chunk.x+16) * 16 + x) * factor magz = ((chunk.z+16) * 16 + z) * factor height = octaves2(magx, magz, 6) height *= 15 height = int(height + 70) column = chunk.get_column(x, z) if abs(chunk.heightmap[x, z] - height) < 10: column.fill(blocks["air"].slot) else: height = height - 30 + randint(-15, 10) column[:height].fill(blocks["air"].slot)
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)
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)
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) for i, j in product(xrange(WIDTH), xrange(HEIGHT)): count += 1 if count >= counts[0]: print "Status: %d/%d (%.2f%%)" % (count, total, count * 100 / total) counts.append(counts.pop(0) * 10) # Get our scaled coords xcoord = x + w * i / WIDTH ycoord = y + h * j / HEIGHT # Get noise and scale from [-1, 1] to [0, 255] if xoffset or yoffset: noise = offset2(xcoord, ycoord, xoffset, yoffset, options.octaves) if options.octaves > 1: noise = octaves2(xcoord, ycoord, options.octaves) else: noise = simplex2(xcoord, ycoord) pbo[i, j] = int((noise + 1) * 127.5) image.save("noise.png")
def test_identity(self): for i in range(512): self.assertEqual(simplex(i, i), octaves2(i, i, 1)) for i in range(512): self.assertEqual(simplex(i, i, i), octaves3(i, i, i, 1))
#!/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
def time_octaves2(i): octaves2(i, i, 5)