prompt.py
This script demonstrates how to gather input from the user at startup.
#################################################################
# WorldViz Copyright 2002
#
# This script demonstrates how to retrieve information
from #
# the user during startup by using the prompt dialog
box. #
#
#
# In this example we will use the number that is typed
into #
# the text field to determine how fast to spin the
ball #
#
#
# If Option 1 is checked we will add another ball
to the #
# scene.
#
#
#
# If Option 2 is checked we will set the background
color #
# to blue.
#
#
#
# We will also ask the user for their name and favorite
#
# color in order to create a 3D text object from it.
#
#
#
#################################################################
import viz
# Start Vizard with a prompt dialog box
viz.go(viz.PROMPT)
import vizinfo
vizinfo.add('This
script demonstrates how to gather input from the user at startup.')
#Retrieve text from the prompt
speed = viz.get(viz.INITMESG)
#Ask user for name
name = viz.input('What is your name?')
choices = ['Blue','Green','Orange']
colors = [[0,0,1],[0,1,0],[1,0.5,0]]
#Ask user for favorite color
favColor = viz.choose('Which of the following colors is your
most favorite?',choices)
#Create text object of user name
text = viz.addText(name,pos=(0,3,10),color=colors[favColor])
# Try to convert the text into a number.
# If the text is invalid, then set the rotation speed to
90.
try:
rotateSpeed = float(speed)
except:
rotateSpeed = 90
# Add the ball and move it in front of the viewer
ball = viz.add('ball.wrl',pos=(0,1.5,4))
ball.addAction(vizact.spin(0,1,0,rotateSpeed))
# Initialize the second ball to 0
ball2 = 0
# If Option 1 is checked then add the
# second ball and space both balls apart
if viz.get(viz.OPTION1):
ball2 = ball.clone()
ball.setPosition([-1,1.5,4])
ball2.setPosition([1,1.5,4])
ball2.addAction(vizact.spin(0,1,0,-rotateSpeed))
# If Option 2 is checked then set the
# background color to blue
if viz.get(viz.OPTION2):
viz.clearcolor(0.5,0.5,1)