# This script will show you how to use the API
# by creating a little terrain animation with
# InstantTerra
import time
# Import the class InstantTerra from the package wysilab
from wysilab import InstantTerra
# Prepare some variables for our animation
frame_per_second = 10 # Frame per second
duration = 3.0 # Duration of the translation
speed = 1.0 # Distance per second
terrain_width = 256 # Width of the terrain
terrain_height = 256 # Height of the terrain
# Name of ouput picture: pic_001.tif, pic_002.tif...
export_filename = "pic_%03d.tif"
# Create an instance of InstantTerra
it = InstantTerra()
# Get project, graph
project = it.project
graph = project.graph
# To get the perlin noise, we just have to get
# the first node of the list.
# To get the export node, we just have to get
# the last node of the list.
# The default project is composed of [Perlin noise, Apply curve, Export]
perlin_noise = graph.get_all_nodes()[0] # First node of the list
export = graph.get_all_nodes()[-1] # Last node of the list
# Set the width and height of the terrain
perlin_noise.set_parameter("width", str(terrain_width))
perlin_noise.set_parameter("height", str(terrain_height))
# We have to know how many frame will compose our animation
total_frames = int(frame_per_second * duration)
# We also have to know the translation step of each frame
translation_step = speed / frame_per_second
# We can now start to compute the animation
for frame_index in range(total_frames):
next_offset = frame_index * translation_step # Compute the next offset
perlin_noise.set_parameter("offset_x", str(next_offset)) # Apply the offset
# We have to set the output filename and export it
filename = export_filename % frame_index
export.set_parameter("file_name", filename)
project.export_all()
# Just print a message to show the progress
print("Frame %d of %d \r"%(frame_index+1, total_frames), end='\r', flush=True)
# Print a message when the script is over
print("Done!")
# We have to close the instant properly
it.close()