def _generate_river(self, noise): # TODO seriously starting to feel like i need a Feature type for these # things? like, passing `noise` around is a really weird way to go # about this. what would the state even look like though? ''' # TODO i think this needs another flooding algorithm, which probably # means it needs to be a lot simpler and faster... noise_factory = discrete_perlin_noise_factory( *self.region.size, resolution=2, octaves=1) noise = { point: abs(noise_factory(*point) - 0.5) * 2 for point in self.region.iter_points() } for point, n in noise.items(): if n < 0.2: self.map_canvas.set_architecture(point, e.Water) return ''' # Build some Blob internals representing the two halves of the river. left_side = {} right_side = {} river = {} center_factory = discrete_perlin_noise_factory( self.region.height, resolution=3) width_factory = discrete_perlin_noise_factory( self.region.height, resolution=6, octaves=2) center = random_normal_int( self.region.center().x, self.region.width / 4 / 3) for y in self.region.range_height(): center += (center_factory(y) - 0.5) * 3 width = width_factory(y) * 2 + 5 x0 = int(center - width / 2) x1 = int(x0 + width + 0.5) for x in range(x0, x1 + 1): self.map_canvas.set_architecture(Point(x, y), e.Water) left_side[y] = (Span(self.region.left, x0 - 1),) right_side[y] = (Span(x1 + 1, self.region.right),) river[y] = (Span(x0, x1),) return Blob(left_side), Blob(river), Blob(right_side)