Tutorial: Python Programming 101

An example

So what does all this have to do with virtual worlds? Let's run a script in Vizard and see. Open a new vizard file by going to “New Vizard File” and choosing “Vizard File” this time.  Save the new file giving it a name you like and placing it in a convenient location.

 

In this script, we'll treat some 3D objects as variables and manipulate them with some of our logic. The following lines will create a row of ducks with a “for” statement. Read through them and then run the script:

 

import viz
import vizact

viz.setMultiSample(4)
viz.fov(60)
viz.go()

#Create an empty array to put some ducks in.
team = []
#Go through a loop six times.
for eachnumber in range(6):
    #Each time you go through the loop, create a new duck and
    #scale it down to a smaller size.
    newduck = viz.addAvatar('duck.cfg')
    newduck.setScale([.5,.5,.5])

    #Place the new duck on the x-axis.
    #Each time the script goes through the loop, "eachnumber"
    #will be one larger so the ducks will fall in a line
    #along the x-axis
    newduck.setPosition([eachnumber, 0,5])

    #Add the new duck to the "team" array.
    team.append(newduck)

    #If the new duck is one of the first two created,
    #make it spin around the x #axis.
    if eachnumber < 2:
        newduck.add(vizact.spin(1,0,0,90))
    #If the new duck is one of the second two, make it spin around the y axis.
    elif eachnumber >= 2 and eachnumber < 4:
        newduck.add(vizact.spin(0,1,0,90))
    #If the new duck is one of the remaining two,
    #make it spin around the z axis.
    else:
        newduck.add(vizact.spin(0,0,1,90))

#move the view to see all ducks
viz.MainView.move([2.5,-1,0])

 

Now run your script.

 

 

 

 

 

 

Speaking Vizard's language

A quick note: Tips on scripts

Looping logic

If-then logic

Functions

An example

More about Python