Esempio n. 1
0
def generate_simplex_noise_terrain(nodes, random_seed=117, altitude_feature=["terrain", "altitude"]):
        """
        Set altitude feature using simplex noise.

        Want to set feature value on all nodes (no criteria), with the value determined by
        simplex noise. Noise object is set up in a closure getter function, with the inner function
        accepting a node and feature_keys list. The node's own data is then used to determine the
        noise value, by querying SimplexNoise object then calling node.set_feature(...)
        random.seed(seed)
        """
        random.seed(random_seed)
        weight = 1
        nodetools.set_all_nodes_feature_with_funcs(nodes=nodes,
                                                   feature=altitude_feature,
                                                   valuators=[(nodeval.get_simplex_noise_valuator(random_seed), weight)],
                                                   criteria_funcs=[])
Esempio n. 2
0
def refine_coastlines(seed, world):
    # Want to find all coastal nodes with an altitude between -0.01 and 0.01, and use
    #  the latitude and longtiude of these points as locations to refine. This increases coastal
    #  smoothness. Warning! Reset random.seed before both altitude generation routines, or
    #  the extra cells we just generated will no longer be on the coast.
    coastal_test = nodetools.get_criteria_func([
        (["terrain", "altitude"], operator.lt, 0.02),
        (["terrain", "altitude"], operator.gt, -0.02),
    ])
    locations_to_refine = map(lambda n: (n.latitude, n.longitude),
        filter(coastal_test, world.all_boundary_nodes)
    )
    print("Coastal locations to refine: %d" % len(locations_to_refine))
    world.refine_voronoi_nodes_around_locations(locations_to_refine)
    random.seed(seed)
    weight = 1
    nodetools.set_all_nodes_feature_with_funcs(nodes=world.all_boundary_nodes,
                                               feature=["terrain", "altitude"],
                                               valuators=[(nodeval.get_simplex_noise_valuator(seed), weight)],
                                               criteria_funcs=[])