next up previous
Next: Implementation Up: The IVL Language Previous: Executing Scripts

Examples

This section provides a series of eight examples that illustrate many of features of the IVL language. The identifiers in these examples have been kept simple, but the full range of C identifiers is allowed.

Draw a cone with with two balls and a cylinder:

a = Cone
b = Sphere
c = Cylinder
d = Sphere
draw a
draw b to the left of a
draw c to the right of a
draw d above a

Draw the same objects as the previous example, but set the color of the objects and use more complicated position modifiers. Note the use of and and the comma for an English-like syntax:

a = Cone
a.diffuseColor = [.3 .2 .7]
b = Sphere
b.diffuseColor = [0 .5 .5]
c = Cylinder
c.diffuseColor = [.25 0 .1]
d = Sphere
d.diffuseColor = [.4 .2 0]
draw a
draw b to the left of a, above a and behind a
draw c in front of b
draw d to the right of b

Draw a big flat red sheet with a blue and a green cylinder on it:

base = Cube
base.diffuseColor = [1 0 .0]
base.scaleFactor = [ 6 .2 6]
fl = Cylinder
fl.diffuseColor = [0 0 1]
fr = Cylinder
fr.diffuseColor = [0 1 0]
draw base
draw fl above base
draw fr above base to right of fl

Define a new object class. Note the use of distances in the modifiers so that the objects are not butted up against each other:

class ConeBall = ``coneball.wrl.gz''
a = ConeBall
b = ConeBall
draw a
draw b 2 to the left of a

Draw a staircase, save it and draw another staircase right next to it:

a = Cube
b = Cube
c = Cube
draw a
draw b behind a
draw c above b
save as ``step.wrl''
class Step = ``step.wrl''
d = Step
// Note that d will be down 1 unit
// from a.  This is normal since the
// new object, d, has a center
// at 0,0,0; the old object is
// centered at 0,1,0
draw d to the left of a

Draw a cone and two objects which are animated according to data in files d and d2:

a = Cone
b = Sphere
c = Cube
a.diffuseColor = [.25 .25 .75]
b.diffuseColor = [1 0 .5]
draw a
draw b above a
draw c to the left of a
translate b with ``d2''
translate c with ``d''

Put some text up:

a = AsciiText
a.diffuseColor = [.937 .517 .08235]
a.string = "Eat at Joe's"
draw a

Robot from page 58 of The Inventor Mentor[15]:

// Define a leg
thigh = Cube
thigh.scaleFactor = [ .6 1.1 .6]
calf = Cube
calf.scaleFactor = [ .5 1.1 .5]
foot = Cube
foot.scaleFactor = [.4 .4 1]
draw foot
draw calf above foot and -1 behind foot
draw thigh above calf
save as ``leg.iv''

// Construct robot
head = Sphere
head.scaleFactor = [1.5  1.5  1.5]
body = Cylinder
body.scaleFactor = [2.5  3  2.5]

draw head
draw body below head

class Leg = ``leg.iv''
lleg = Leg
rleg = Leg
draw lleg below body and -2.25 to the left of
     body and -3.1 in front of body
draw rleg 0.5 to the right of lleg

  
Figure 1: View of ``Robot'' from the IVL viewer



Timothy F. Rohaly
Terence J. Parr
Mon Sep 11 11:59:26 EDT 1995