Lab 2, Exercise 3: Labels

Our programs will produce a considerable amount of numerical data.  Usually, an animation will represent this data by simply moving objects in the animation scene.  But often, we need to keep up with the numerical data directly.  The easiest way to do this is display numerical data in a label: a special text-box that appears inside the animation scene.

Because a label is an animation object, you will see the animation window when you execute your code for this exercise. In the code below, we will display the initial speed you enter for the rocket.

Start with your program from Exercise 2, and resave it with the new filename YourName_Lab2_PHYS495_3.py.

Next, add the following lines at the end of the existing code:

#---------------------------------------------------------
# Create a label for the flight data
#---------------------------------------------------------

flight_data = label()

flight_data.box = 1 # turns on a border around the label
flight_data.opacity = 0 # sets opacity of the background

flight_data.pos = vector(100,100,0) # near the upper-right corner

flight_data.text = ("Flight data\n"
                    "vy = %3.6f" %v)

print "Program Finished."

 

Next, hit the F5 key to execute your program. Enter the initial speed of 50 for the rocket. You should see something like this:

data labels in the animation scene

Next: Exercise 4
Previous: Exercise 2
Go back to the Lab 2 main page.