Scripting Example

<< Previous: Scripting Functions

Next: Common Problems and Possible Solutions >>

This example shows how to use some of the Cosmographia scripting interface functions.
#
# This example script makes the program take users for a 2 minute trip
# to the Earth and Moon.
#
# Import Cosmographia scripting module.
#
import cosmoscripting
cosmo = cosmoscripting.Cosmo()

#
# Display a welcome message that will stay on the screen for 3 seconds.
# Make Cosmographia wait for 4 seconds before moving onto the next step
# to give users a chance to read the message. In subsequent blocks the
# script will use displayNote to display a message before each set of
# commands but the post-message wait times will be smaller to make
# messages stay on the screen just as the steps themselves start being
# executed.
#
cosmo.displayNote( "Welcome to Cosmographia Scripting Example!", 3 ).wait( 4 )

#
# Use hideToolBar to hide the left toolbar. Use hideStatusMessages to hide
# program's default status messages that might colide with
# annotations displayed by calls to displayNotes. Use hideInfoText to
# to hide informational blocks at the top left and top right corners.
# Use showFullScreen to switch to full screen mode. All commands are 
# instanteneous and will occur during the 4 second wait set by wait.
#
cosmo.displayNote( "Switch to full screen, hide toolbar and info text", 3 ).wait( 4 )
cosmo.hideToolBar()
cosmo.hideStatusMessages()
cosmo.hideInfoText()
cosmo.showFullScreen()

#
# Use gotoHome to go to the Solar System "home" view. Use 
# setCameraToInertialFrame and setTimeRate to set the rendering
# frame to ICRF and the time rate to 1 second/second. The total time 
# to run the commands below will be 7 seconds -- 1 second set by wait 
# after displayNote + 5 seconds used by gotoHome + 1 second set by 
# wait after gotoHome. The setCameraToInertialFrame and setTimeRate 
# commands are instantaneous.
#
cosmo.displayNote( "Start with the Solar System home view", 3 ).wait( 1 )
cosmo.setCameraToInertialFrame()
cosmo.setTimeRate( 1 )
cosmo.gotoHome( 5 )
cosmo.wait( 1 )

#
# Set time using setTime to 2015-10-31 23:50:00 UTC. The total time to
# run the commands below will be 3 seconds -- 2 in wait + another 1 in
# wait. The setTime command is instantaneous.
#
cosmo.displayNote( "Set time to 2015-10-31 23:50 UTC", 2 ).wait( 2 )
cosmo.setTime( "2015-10-31 23:50:00 UTC" )
cosmo.wait( 1 )

#
# Use gotoObject to go to Earth. gotoObject will set Earth as the
# center and select it, and will also set the rendering frame to
# inertial. The total time to run the commands below will be 7 seconds
# -- 1 in wait + 5 in gotoObject + 1 in wait.
#
cosmo.displayNote( "Fly to Earth", 3 ).wait( 1 )
cosmo.gotoObject( "Earth", 5 )
cosmo.wait( 1 )

#
# Use moveAwayFromCenter to back up the camera away from Earth by
# 10,000 km in 3 seconds. Use circleCenterRight to move the camera
# around the Earth in the camera horizontal plane doing a full loop
# (360 degrees) around the Earth in 5 seconds. The total time to run
# the commands below will be 10 seconds -- 1 in wait + 3 in
# moveAwayFromCenter + 5 in circleCenterRight + 1 in wait.
#
cosmo.displayNote( "Back up a bit and fly around Earth", 3 ).wait( 1 )
cosmo.moveAwayFromCenter( 10000, 3 ).wait( 1 )
cosmo.circleCenterRight( 360.0, 5 )
cosmo.wait( 1 )

#
# Use moveToPov to move the camera to a point above North America,
# pointing down at it. [0,-14000,11500] is the desired location in the
# Earth body-fixed frame and the vector opposite to the location --
# [0,1.4,-1.15] -- is the desired direction in which the camera will be
# looking. The vertical direction of the view will be aligned with the
# Earth north pole -- [0,0,1]. The total time to run the commands below
# will be 7 seconds -- 1 in wait + 5 in moveToPov + 1 in wait.
#
cosmo.displayNote( "Look down at North America", 3 ).wait( 1 )
cosmo.moveToPov( "Earth", [0,-14000,11500], [0,1.4,-1.15], [0,0,1], 5 )
cosmo.wait( 1 )

#
# Use pointAtObject to point at the Sun. The total time to run the 
# commands below will be 4 seconds -- 1 in wait + 2 in pointAtObject 
# + 1 in wait.
#
cosmo.displayNote( "Point at the Sun", 3 ).wait( 1 )
cosmo.pointAtObject( "Sun" )
cosmo.wait( 1 )

#
# Use pointAtObject to point at the Moon. The total time to run the 
# commands below will be 4 seconds -- 1 in wait + 2 in pointAtObject 
# + 1 in wait.
#
cosmo.displayNote( "Point at the Moon", 3 ).wait( 1 )
cosmo.pointAtObject( "Moon" )
cosmo.wait( 1 )

#
# Use moveToPov to move the camera to a point above the Moon's near
# side. [5000,0,0] is the location in the Moon body-fixed frame and the
# vector opposite to the location -- [-1,0,0] -- is the direction in
# which the camera will be looking. The vertical direction of the view
# will be aligned with the Moon's north pole -- [0,0,1]. The total time
# to run the commands below will be 7 seconds -- 1 in wait + 5 in
# moveToPov + 1 in wait.
#
cosmo.displayNote( "Fly to the Moon and look at its near side", 4 ).wait( 1 )
cosmo.moveToPov( "Moon", [5000,0,0], [-1,0,0], [0,0,1], 5 )
cosmo.wait( 1 )

#
# Use showBodyFixedFrame, showLatLongGrid, and showDirectionVector
# to show Moon's body-fixed frame, latitude-lognitude grid and 
# directions to Earth and Sun. The total time to run the commands below 
# will be 6 seconds -- 1 in each of 6 waits. All other commands are 
# instanteneous.
#
cosmo.displayNote( "Show Moon's frame and lon-lat grid", 2 ).wait( 1 )
cosmo.showBodyFixedFrame( "Moon" ).wait( 1 )
cosmo.showLatLongGrid( "Moon" ).wait( 1 )
cosmo.displayNote( "Show directions to Sun and Earth", 2 ).wait( 1 )
cosmo.showDirectionVector( "Moon", "Sun" ).wait( 1 )
cosmo.showDirectionVector( "Moon", "Earth" ).wait( 1 )

#
# Use circleCenterUp to place the camera above the Moon's north pole.
# The total time to run the commands below will be 4.5 seconds -- 1 in
# wait + 2.5 in circleCenterUp + 1 in wait.
#
cosmo.displayNote( "Look at the Moon's North pole", 3 ).wait( 1 )
cosmo.circleCenterUp( 90.0, 2.5 )
cosmo.wait( 1 )

#
# Use circleCenterDown to place the camera above the Moon's south pole.
# The total time to run the commands below will be 7 seconds -- 1 in
# wait + 5 in circleCenterDown + 1 in wait.
#
cosmo.displayNote( "Look at the Moon's South pole", 3 ).wait( 1 )
cosmo.circleCenterDown( 180.0, 5 )
cosmo.wait( 1 )

#
# Use circleCenterUp and circleCenterRight to move the camera above the
# Moon's far side in two motions, first back to the near side of the
# Moon, then around the Moon's equator to the far side. The total time
# to run the commands below will be 9.5 seconds -- 1 in wait + 2.5 in
# circleCenterUp + 5 in circleCenterRight + 1 in wait.
#
cosmo.displayNote( "Look at the Moon's far side", 3 ).wait( 1 )
cosmo.circleCenterUp( 90.0, 2.5 )
cosmo.circleCenterRight( 180.0, 5 )
cosmo.wait( 1 )

#
# Use craneUp to move the camera along the vertical direction to look
# at the Earth over the Moon's limb. The total time to run the commands
# below will be 4 seconds -- 1 in wait + 2 in craneUp + 1 in wait.
#
cosmo.displayNote( "Look over the Moon's shoulder at the Earth", 3 ).wait( 1 )
cosmo.craneUp( 2000.0, 2.0 )
cosmo.wait( 1 )

#
# Use trackObject to switch the rendering frame to the locked frame
# based on the Moon-Earth direction and speed up time to 1 day/second
# to show the sky moving behind the Earth while the Moon-Earth
# direction stays constant. The total time to run the commands below
# will be 10 seconds -- 3 in wait + 7 in wait. The Trackobject and
# setTimeRate commands are instantaneous.
#
cosmo.displayNote( "Switch view to track Earth", 3 ).wait( 4 )
cosmo.trackObject( "Earth" )
cosmo.displayNote( "Speed up time to see the sky pass behind it", 3 )
cosmo.setTimeRate( 24*60*60 ).wait( 7 )

#
# Use pause to stop time, use pointAtObject to point at the 
# Sun, and use unpause to have time run again. The total time to 
# run the commands below will be 6 seconds -- 1 in wait + 
# 2 in wait + 2 in pointAtObject + 1 in wait. The pause 
# is instantaneous.
#
cosmo.displayNote( "Stop time and point at the Sun", 3 ).wait( 1 )
cosmo.pause()
cosmo.wait( 2 )
cosmo.pointAtObject( "Sun" )
cosmo.wait( 1 )
cosmo.unpause()

#
# Use gotoHome to go to the Solar System "home" view. Use
# setCameraToInertialFrame and setTimeRate to set the rendering
# frame to ICRF and the time rate to 1 second/second. The total time
# to run the commands below will be 8 seconds -- 1 in wait + 5 in 
# gotoHome + 2 in wait. The setCameraToInertialFrame and setTimeRate
# commands are instantaneous.
#
cosmo.displayNote( "Go back to the Solar System home view", 3 ).wait( 1 )
cosmo.setCameraToInertialFrame()
cosmo.setTimeRate( 1 )
cosmo.gotoHome( 5 )
cosmo.wait( 2 )

#
# Reset all visual attributes and settings that we changed.
# All commands are instanteneous and will occur during the 3 
# second wait set by wait.
#
cosmo.displayNote( "Switch to normal window, restore changed settings", 3 ).wait( 4 )
cosmo.hideBodyFixedFrame( "Moon" )
cosmo.hideLatLongGrid( "Moon" )
cosmo.hideDirectionVector( "Moon", "Sun" )
cosmo.hideDirectionVector( "Moon", "Earth" )
cosmo.showToolBar()
cosmo.showStatusMessages()
cosmo.showInfoText()
cosmo.showNormalWindow()

#
# Finish by displaying a "Goodbye" message.
#
cosmo.displayNote( "It was fun! Goodbye ...", 3 ).wait( 3 )

#
# End of the example script.
#