<jupyter_start><jupyter_text>Sample Function: Perlin Noise in 2D===================================Here we use `pyvista.core.imaging.sample_function`{.interpreted-textrole="func"} to sample Perlin noise over a region to generate randomterrain.Perlin noise is atype of gradient noise often used by visual effectsartists to increase the appearance of realism in computer graphics.Source: The development of Perlin Noise has allowed computer graphics artists tobetter represent the complexity of natural phenomena in visual effectsfor the motion picture industry.<jupyter_code>import pyvista as pv<jupyter_output><empty_output><jupyter_text>Generate Perlin Noise over a StructuredGrid===========================================Feel free to change the values of `freq` to change the shape of the\"mountains\". For example, lowering the frequency will make the terrainseem more like hills rather than mountains.<jupyter_code>freq = [0.689, 0.562, 0.683]
noise = pv.perlin_noise(1, freq, (0, 0, 0))
sampled = pv.sample_function(noise,
                             bounds=(-10, 10, -10, 10, -10, 10),
                             dim=(500, 500, 1))<jupyter_output><empty_output><jupyter_text>Warp by scalar==============Here we warp by scalar to give the terrain some height based on thevalue of the Perlin noise. This is necessary to the terrain its shape.<jupyter_code>mesh = sampled.warp_by_scalar('scalars')
mesh = mesh.extract_surface()

# clean and smooth a little to reduce Perlin noise artifacts
mesh = mesh.smooth(n_iter=100, inplace=False, relaxation_factor=1)

# This makes the "water" level look flat.
z = mesh.points[:, 2]
diff = z.max() - z.min()

# water level at 70%  (change this to change the water level)
water_percent = 0.7
water_level = z.max() - water_percent*diff
mesh.points[z < water_level, 2] = water_level<jupyter_output><empty_output><jupyter_text>Show the terrain as a contour plot<jupyter_code># make the water blue
rng = z.max() - z.min()
clim = (z.max() - rng*1.65, z.max())

pl = pv.Plotter()
pl.add_mesh(mesh, scalars=z,
            cmap='gist_earth', n_colors=10, show_scalar_bar=False,
            smooth_shading=True, clim=clim)
pl.show()<jupyter_output><empty_output><jupyter_text>Show the terrain with custom lighting and shadows<jupyter_code>pl = pv.Plotter(lighting=None)
pl.add_light(pv.Light((3, 1, 0.5), show_actor=True, positional=True,
                      cone_angle=90, intensity=1.2))
pl.add_mesh(mesh, cmap='gist_earth', show_scalar_bar=False,
            smooth_shading=True, clim=clim)
pl.enable_shadows = True
pl.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13366718027734978, 'fraction_numerical': 0.022727272727272728, 'mean_word_length': 4.8623024830699775, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '210323', 'license': 'MIT', 'n_tokens_mistral': 872, 'n_tokens_neox': 809, 'n_words': 246, 'path': 'sampling_functions_2d.ipynb', 'repo_name': 'UttamBasu/ipygany_examples', 'size': '2596'}