Tutorial Project 6: A 3D Graphics Animation

This project is introduces the Graph3D Objects. In the project, we build a one-page Document called "Revolutions". The finished version of this Document (with an additional page) appears at the New Mathwright Library and Cafe ( http://www.mathwright.com ) under the name "Revolutions of Surfaces" and you may compare your results with the first Interaction page of that.

In Revolutions, you may define and graph a function, f(x) of a single variable. You define the function, choose the domain and draw the space graph using the Control Panel:

Next, you may select a start angle (degrees) and an end angle through which to rotate the graph. The surface that is "swept out" is drawn in yellow, and the beginning graph is drawn in green, and the end graph is drawn in red. Use the Control panel below for that.

3D Graphics is an enormous topic in Mathscript. We will not even pretend in this Tutorial to cover all the bases. For a detailed description of the Graph3D objects, we recommend that you peruse Welcome to Mathscript 3D in the reference section. In this tutorial, we will explore space graphs, space curves, and surfaces as we build a simple Microworld that illustrates how graphs may be rotated to sweep out surfaces.

This work will have two parts: Screen Design and Scripting. We focus on all of the Screen Design in Part 1 of this Tutorial, and on the Scripting in Part 2.

Part 1: Screen Design

Step 1: Document Directory

Before you begin, be sure that the screen resolution is 800x600 or 1024x768. The Documents that you create may be displayed on reader machines or browsers in any resolution. You have no control over that. But if you create them in 800x600 or 1024x768 resolution, then they will display properly in 640x480, 800x600, or 1024x768 resolutions in the reader's machine or browser. This is especially important because, in the browsers, you may shrink or enlarge the page as you like to fit your web page. Along these lines, we remind you that if you use wallpaper bitmaps (and hotspots) then you may use either bitmaps, GIFs, or JPGs. And these should be 800x600, or 1024x768 pixels to match your screen resolution.

You set the screen resolution by right-clicking on the background screen to get the menu, and then selecting Properties. Under Settings, choose 800x600 or 1024x768 screen resolution. The colors should be High Color (16 Million or 2^24 Colors).

We begin by creating the "Document Directory". Every Document should be placed in its own directory. The reason for this is that Documents often have auxiliary files called resources, such as bitmap files and sound files. When a Document is placed on the server, all of its resources need to be packaged together so that MathwrightWeb knows where to find them.

When the Document is viewed by a reader in Applet mode, MathwrightWeb brings these resources to the user's web cache one at a time, as needed. Any particular resource is downloaded only once. The next time it is needed (If the reader returns to a page, say, or reopens the Document at a later time) the resource is simply loaded from the cache. If, however, for some reason, the resource is removed from the cache, then MathwrightWeb will go back to the server to get another copy of the resource.

Therefore, the first step in creating the revolutions Document is to create a directory called revolutions that will hold it. We use lowercase for all file names and directories because some servers (notably Apache servers) are case sensitive, and may not find a file if the case is wrong. Of course, this is not an issue for Mathwright32 Author or Reader when they read Documents offline, but we follow the practice outlined above because most Documents will be served from web servers.

Another practice that we follow for reasons that will be clear when you read the final Project on Packaging and Delivering your Document, is this: The name of the directory should be the same (lowercase) name as the name of your Document ( .lva file). We will create Documents in the C:\My Documents folder, because that is where Mathwright32 looks for them.

Thus, go to the Windows Explorer, select the C:\My Documents directory, then select File, New, Folder: and when asked for a name, type revolutions. This will create a directory: C:\My Documents\revolutions\ into which you will place the Document.

Step 2: Adding the "handcursor.cur" resource

If you browse in Windows Explorer to the home directory: Program Files/Bluejay Lispware/Mathwright32 Author you will find a little file called: handcursor.cur Whenever you create a new Document, copy this file and paste it into your new directory. While it is not needed for offline reading in Mathwright32, it is a necessary resource for MathwrightWeb. Thus, highlight it, and select: Edit, Copy. Then browse to your new directory, and select Edit, Paste.

Step 3: Creating the Document

Next, let's open Mathwright32 Author to create the revolutions Document. There are several ways to open Mathwright32 as we saw above. You may click on the Mathwright Author 32 icon above in the MWAuthor32 button on the Start Menu that was set up with the system, or you may go to Windows Explorer and click on mwauthor.exe in the Program Files/Bluejay Lispware/Mathwright32 Author subdirectory, or you may select Run..., then enter C:/Program Files/Bluejay Lispware/Mathwright32 Author\mwauthor.exe.

Any of these will open a blank copy of the program. Now, once the program is open, select WorkBook, New Microworld from the menu. The screen will turn white, and the page caption will change to: Untitled0: Page 1 of 1 This means that you have created a new Document. It has the temporary name: Untitled0.lva.

Mathwright32 Author wakes up in Reader Mode. You may change to Design mode if you like by selecting "Go to Design mode" in the WorkBook menu above. The advantage of being in Design mode is that certain objects that you create, such as push buttons and text fields, will be moveable and resizeable in this mode, and will not be activated when the mouse clicks on them. In Design mode, you may copy and paste objects or whole pages, may insert or delete pages, and so on.

On the other hand, Reader mode is where you give objects their specific properties, create and run scripts, and save the Document to disk.

Step 4: Setting the Page color

Now, let's set the page color for the Document. The "default" page color for a book is white. Each new page that you place in a Document will have this default color. When you set the page color for the Document, you change the default background color to a new color. That changes the color of the current page, and of each new page that will be added subsequently.

Select Page, Page Background color... A dialog box will appear with a selection of colors to choose from. Select the light grey in the sixth row, sixth column, as marked below:

The screen should change to light grey. This light grey will be the default background color for all new pages. You may still change the background color for any particular page by selecting: Page, Page Background Color... on any page.

The next step is to go to Design Mode and create an object so that we can save this Microworld. There are 13 types of Objects (or Gadgets) that you may create in Design Mode. These are: Button Gadgets, CheckBox Gadgets, CommandField Objects, Data Table Objects, Graph2D Gadgets, Graph3D Objects, HotSpot Gadgets, Label Objects, MathEdit Objects, Horizontal Slider Gadgets, Vertical Slider Gadgets, TextBox Objects, and TextField (or TextLine) Gadgets.

To create any of these, you must place Mathwright in Design mode. This is done by the menu selection: WorkBook, Go to Design mode.

Mathwright always opens up in Reader mode. Next, select the Type of Object to create from the Objects menu. Select Label Object. We will create a simple Label.

Now, once you have selected Label Object, the cursor will change to a "pointing finger ". This indicates that you are expected to draw the outline of the object on the screen. Do this in 4 steps:

Usually, a "ghost rectangle" will be traced as you move the mouse to help you see what you have at any moment, but if you are drawing on the surface of another window, you will not see a ghost rectangle. Once you have drawn the rectangle, you will generally be asked for a name. In the case of a Label, you will not. We will name it in Reader Mode. See the picture of the completed Microworld at the beginning of this Tutorial for an idea where to put it. If you do not get it right first time, don't worry. You can resize and move it while in Design Mode. Thus, return to Reader mode.

This is done by the menu selection: WorkBook, Go to Reader mode. You should see in the upper left corner something like the following (except that the Title of the book is not changed yet in your version):

Next, access the menu for the new Label by right-clicking on the blank white rectangle.. You will see one option available: Edit the Label. This option is only available in Mathwright32 Author. In Mathwright32 Reader and MathwrightWeb, Labels do not have menus. They really are a part of the background page. Select that, and the other menu options become available, and you may enter text in the Label now.

First, select Set Background Color... and choose the same light grey color you used for the page. The Label disappears! Actually, you see that there is a blinking caret where it was, so it is not really gone. It just blends with the background now.

Next, select Set Font... and change the Font to Arial, 24 pt, Bold. Then click on the label and type the text:

Surfaces of Revolution

You should see something like this (except that the Title of the book is still not changed yet in your version)::

If it did not fit, then just return to Design Mode and resize the Label, then return to Reader Mode.

Now, follow the instructions below to Save the Document.

Step 5: Saving Changes

As you make changes, we recommend that you save those changes frequently. The procedure for doing that follows.

Get into Reader mode, and Select WorkBook, Save As...

And type in the Dialog Box C:\My Documents\revolutions\revolutions or, select the C:\My Documents\revolutions directory, then type revolutions in the dialog box as below. Save the Document. It is saved as revolutions.lva.

As you develop your book, frequently follow a procedure similar to this one for saving the book for the first time. And every now and then, back up your work by copying the directory to disk, or at least to a different directory. Nothing is more frustrating than losing a day's (or a week's) work in the ether after a system or program crash.

Simply select WorkBook, Save, and the changes will be saved to the file: revolutions.lva, which is the Document File that you would open in Mathwright32 Author or Reader. It is good practice to do this from time to time, and of course, for projects in which you have invested a fair amount of time, you should save a "backup" copy of your .lva file to some other place, such as a floppy disk, or another directory occasionally.

Next, we will create a Graph3D object and place it directly below the label we just made.

To create this, you must place Mathwright in Design mode. This is done by the menu selection: WorkBook, Go to Design mode.

 

Step 6: Creating a Graph3D Object

We are nearly ready to draw a Graph3D object on the screen. This is where the graphs will be drawn. The procedure that we will use applies to all Display Objects and Gadgets. Read and follow the procedure outlined below to build a Graph3D object with the name: graph. Use the illustrations below as a guide, or see the picture of the completed Microworld at the beginning of this Tutorial for an idea how to draw it. .

Before drawing the Graph3D Object:

After drawing the Graph3D Object (in Design Mode):

After drawing the Graph3D Object (in Reader Mode):

How to create Display Objects and Gadgets from the Object Menu

Usually, the first thing that authors do after they have decided what the dynamics of reader interaction on a page should be, is to place appropriate display objects and gadgets on that page. The simplest way to do that is to use the Mathwright32 Objects menu in Design mode. Later, we'll discuss how individual objects, or whole pages may be copied and pasted, but for now, we'll discuss this simplest way to build objects from scratch.

To create any of these, you must place Mathwright in Design mode. This is done by the menu selection: WorkBook, Go to Design mode.

Next, select the Type of Object to create from the Objects menu. In this case, select a Graph3D Object.

Now, once you have selected Graph3D object , the cursor will change to a "pointing finger ". This indicates that you are expected to draw the outline of the object on the screen. Do this in 4 steps:

Once you have drawn the rectangle, you will be asked for a name.

Naming Display Objects and Gadgets

Once you draw the rectangle, you will be asked to name the object (unless it is a HotSpot or a Label). In this case, the name will be graph. Each Display object or Gadget must have a name. The name you supply will be used whenever Scripts refer to the object to get or set information in them. Therefore the names you supply for different objects of the same type on a page should be distinct.

Names will be interpreted as Mathscript Strings, and so should conform to the rules for creating strings. They may contain lower-case letters, spaces and underscores, and they are case-sensitive. Objects on separate pages may have the same name. Also, it is important to refer to objects in Scripts and Commands with exactly the same spelling and case with which the object was named. Any object may be renamed in Design mode by accessing the Rename option on its menu.

When you have typed a name, a captioned window representing the object will appear. The caption will show the name and the type of the object, and the window will show its background color. In Reader mode, you will see the actual object, and be able to set its attributes.

Step 7: Add five more Labels

The next step will be to create the red label in the upper right corner: "Function f(x) to graph:" . Follow the same steps you did earlier and see the picture of the completed Microworld at the beginning of this Tutorial for an idea where to put it. Thus, switch to Design Mode, and Select Objects, Label Object, and draw the label.

Then switch to Reader Mode. Access the menu for the new Label by right-clicking on the blank white rectangle.. You will see one option available: Edit the Label. This option is only available in Mathwright32 Author. Select that, and the other menu options become available, and you may enter text in the Label now:

Function f(x) to graph:

Next, select Set Background Color... and choose the same light grey color you used for the page. The Label blends with the background now. Next, select Set Font... and change the Font to Arial, 16 pt, Bold.

Finally, choose: Set Text Color... from the menu and select the red in the second row, first column. You should see something like what is in the picture at the top of the page.

The next 4 labels will all use the font: Arial, 12 pt, Bold. We will create one, and then use copy and paste to create the others, so that we will not have to set the font each time. We will also use the Snap to Grid option on the Page menu in design mode. This will help us line the labels up with their corresponding textfields. Thus, return to Design Mode, and select Page, Snap to Grid.

Next, create the label: "x varies from:" and return to Reader Mode. Type in the text, and select Arial, 12 pt, Bold font, and a dark blue color.

Now, return to Design Mode. Right click on the new label, and select Copy Object. Next, go to the Objects menu and select Paste Object. The new label is pasted right on top of the old one, so you won't see it right away. Just move the cursor over the old label and drag it away. (Actually, it is the old label you are dragging but, like electrons with the same spin, they are identical.)

Next, move and size the label roughly to where "revolve from degrees:" should be. Go to Reader Mode, Edit the new Label so that the text reads: "revolve from degrees:" and you are done for now. Later, you will line everything up properly.

Now, Save the Document.

Return to Design Mode, and select Paste Object once more. This time, drag away the new Label to where the blue "to" label is, and make it really tiny. Go to Reader Mode, Edit the new Label so that the text reads: "to".

Return to Design Mode, right click on the new label, and select Copy Object. Then select Paste Object once more. Drag away the new "to" Label to where the red "to" label is. Go to Reader Mode, Edit the new Label, choose: Set Text Color... from the menu and select the red in the second row, first column.

Once again, Save the Document.

Step 8: Add five TextField Gadgets

The first TextField will be right below the Function f(x) to graph: Label. Its name will be "revs" For its font, we will choose: Arial, 12 pt, Bold. Thus, go to Design Mode, and select TextField Gadget from the Objects Menu and draw the TextField. You will be asked for a name this time. Type: revs. Case is important. This name will be used in the scripts.

Now, go to Reader Mode. Right click on the new TextField to get the menu, and select: revs: Settings, Text, Set Font as below.

Choose: Arial, 12 pt, Bold. Next, seed the TextField with some arbitrary initial expression in x, such as:

(x+7)*(x-2)*(x-9)/100

Once again, Save the Document.

The next TextField, seeded with text -10 will be directly to the right of the Label "x varies from:". Its name will be "domx11". Thus, go to Design Mode, and select TextField Gadget from the Objects Menu and draw the TextField. You will be asked for a name this time. Type: domx11.

Now, go to Reader Mode. Right click on the new TextField to get the menu, and select: domx11: Settings, Text, Set Font Choose: Arial, 12 pt, Regular. Next, seed the TextField with value -10. This is the left endpoint for the domain of the function we will graph.

The rest is easy. Go to Design Mode, click with the right mouse button to Copy this Field, then select Objects, Paste, to Paste it. The new TextField (beneath the original one) is called, temporarily, "New TextField" Select Rename Object. You will be asked for a name. Name it to domx12 this time. This will be the right endpoint of the domain. Move it to the right of the "to" Label. Go to Reader Mode, then, seed the TextField with value 10.

Do the same for the Textfields "ang1" which will be seeded with value 30, and with TextField "ang2" which will be seeded with value 180. These are, respectively, the start and the stop angles (measured in degrees) for the rotation.

Once again, Save the Document.

Step 9: Add three Button Gadgets

Finally, we must add three Button Gadgets called Graph f, Revolve, and Clear. We can do that entirely in Design Mode. Select Objects, Button Gadget, and draw and name each one. You see where they go in the picture at the top of the screen. The only remaining work to do in the Microworld is to script these Buttons, and to write the Book Script. All of that will be done in Reader Mode. Thus, return to Reader Mode and Save the Document.

Part 2: Scripting

In order for the page to work, we have to write scripts for the pushbuttons and a WorkBook script for the Microroworld itself. Thus, we should say a little bit about creating Scripts in Script Windows. There are just five types of scripts that authors may create. These are: Gadget Scripts, HotSpot Scripts, WorkBook Scripts, Page Scripts, and File Scripts. All scripts are created and edited in Reader mode.

How and where to create Scripts

Every script is created in a Script wndow in three steps. There are no exceptions. To create a script, you must:

Scripts are composed in Script Windows, or Sometimes called Listeners. All Gadgets have their private Script Windows. To edit a Gadget Script, you select: Actions, Edit Script from the Gadget menu. Once a script window is open, you may edit the script. To make the editing changes functional, you should press the Compile button, then Attach and Exit to attach it to the Gadget. If you do not attach it, your script is not saved, unless, of course, you saved it to disk from the File, Save Script As... menu. Often, you will open a Script Window to create a FIle Script, and you will not intend to attach it to the gadget. In this case, press Cancel when finished.

To compile the script, click the Compile button. If the compiler detects no errors, it will notify you with a Success! banner, otherwise, it will attempt to diagnose the error. If the compilation is successful, then you can save your changes as mentioned by pressing the Attach and Exit button, or by selecting File, Save Script As...

The first thing that we need to do is to create a WorkBook Script that will do some initializations for us and define a program that we will need. For that, select the WorkBook, WorkBook Script menu, and open the (empty) script for the Document.

Enter the following script. Notice that each line ends with a semicolon.

Let's look at the lines of the script which merely sets the reading mode and precision and declares a few global variables and functions. By making the declarations here, we may refer to these objects in any later script. Whenever you want objects to be globally defined in a Microworld (and not locally defined in a single script) it is a good idea to declare them in the WorkBook script, or in a File script that the WorkBook script loads.

readfloat; 'sets double reading mode'
precision 7; 'sets numeric precision to 7'
make variable x; 'declare 4 variables'
make variable y;
make variable a;
make variable b;
make f(x) x; 'declare 8 functions'
make g(x) x;
make h(x) x;
make k(x) x;
make f1(x) x;
make f2(x) x;
make k1(x) x;
make k2(x) x;

This script will be run once, when the book opens. Since the book is already open, we should execute it now so that we won't have to close and open the book. Thus click Execute. The script is run, and the definitions are made. Now executing the script does not compile, attach, or save it. That must be done separately, since we might be executing it simply to test it. So now select Compile the Script, and Attach and Exit. The WorkBook Script is in place.

This is a good time to Save the Document by selecting WorkBook, Save.

Step 10: Scripting the PushButtons

We continue by creating the script for PushButton Graph f. To do this, we first have to get the pushbutton menu. Thus, click with the right mouse button anywhere on the pushbutton. The following menu should appear.

Select from it Actions, then Edit Script.

When you do this, the Script Window for Graph f will appear. This is where you create the script. Type the following script in the window. Notice that all but the second line ends with a semicolon. The strings in single quotes are comments and are not read by the compiler.

let pt be evaluate(textlist("revs")); 'check if TextField "revs" is empty'
if length(pt)==0 then { notice("Please enter a function.")} else {


make variable x; 'declare variables'
make variable y;
let h(x) be value evaluate(text("revs")); 'define the function h'
let f(x,y) be [x,h(x)*(1-y),0]; 'define parametric surface'
let k(x) be [x, h(x), 0]; 'define the space curve'
let domx1 be evaluate(text("domx11")); 'define the domain for f(x,y)'
let domx2 be evaluate(text("domx12"));
let domy1 be 0;
let domy2 be 1;
set the surfacerefinement to 30, 30; 'sets refinement of the surface'
set the surfacedomain to [domx1+0.01, domx2-0.01], [domy1, domy2];
set the curvedomain to domx1, domx2;
set the curverefinement to 200;
draw the surface f using color lred;
draw the tube k using color blue width 0.2;


}

The first two lines check whether the TextField "revs" is empty. If it is, a warning message is posted, otherwise we continue with the script.

Continuing, we declare x and y to be variables -- that is, they evaluate to themselves. The next line defines the function h. Notice that h is a function of x, and especially notice the use of the keyword value. We only use value in function definitions, and it causes the actual current value of the evaluate(text("revs")) to be assigned as definition: h(x), rather than causing the TextField to be read each time h is evaluated.

The next line: let f(x,y) be [x,h(x)*(1-y),0]; is interesting. It defines a plane parametric surface in the z=0 plane that will represent the graph filled in to the x axis. It is a function from R2 to R3. The convention in OpenGL is this. The x axis is the red horizontal axis. The y axis is the white vertical axis, and the blue axis, extending out of the screen in positive values towards the viewer, is the z axis.

The next line: let k(x) be [x, h(x), 0]; defines the "space curve" k(x) which is a function of single variable x that will represent the actual graph.

The next 4 lines define the domain rectangle in the xy plane for the parametric surface f(x,y). It reads the x domain from the screen, and sets the y domain to [0,1].

With the lines:

set the surfacerefinement to 30, 30;
set the surfacedomain to [domx1+0.01, domx2-0.01], [domy1, domy2];
set the curvedomain to domx1, domx2;
set the curverefinement to 200;

We respectively determine the xy refinement with which the parametric surface f(x,y) will be drawn, and we actually set the domain in the xy plane of that surface. We give the domain for the space curve k(x) the same interval as the x domain for the function and make the drawing refinement 200.

Finally, the lines:

draw the surface f using color lred;
draw the tube k using color blue width 0.2;

actually draw the parametric surface and space curve. We supply the colors here, and choose the width 0.2 as the radial width for the "tube" that represents the graph itself.

Each of these commands creates a named actor. "f" is the name of the parametric surface, and "k" is the name of the space curve. Later calls to this function will replace the present f and k by the new dfinitions, and will thus replace the object in the Graph3D with the new object.

Next, we have to compile the script. For that, click the Compile button at the bottom of the window. The Success! banner should appear. Click Ok. Then click Attach and Exit. As explained above, this is where you accept the changes made to the script, and connect the new script to the button.

While the appearance of the screen doesn't change, the PushButton Graph f now has the following functionality. When the button is pushed, the current definition for the function and its domain is read, and both the space curve and the parametric surface representing the function are drawn in window graph. Also, named actors are defined in the scene. They remain there until they are replaced (as in when we push the Clear Button) Try it.

This is a good time to Save the WorkBook.

The next thing we want to do is attach the script for the Clear Button. Thus, click with the right mouse button anywhere on the Clear pushbutton. The menu should appear. Select from it Actions, then Edit Script. When you do this, the Script Window for Clear will appear.

Now type the following script in the window. Notice that each line ends with a semicolon.

let f(x,y) be [0,0,0];
let g(x,y) be [0,0,0];
let k(x) be [0,0,0];
let f1(x,y) be [0,0,0];
let f2(x,y) be [0,0,0];
let k1(x) be [0,0,0];
let k2(x) be [0,0,0];
set surfacerefinement to 5,5;
set curverefinement to 10;
surface f;
surface f1;
surface f2;
surface g;
tube k;
tube k1;
tube k2;

All it does is set all functions t the constant [0,0,0] point, reset refinements (for speed) and call either Surface or Tube. Every time Surface or Tube is called, it creates a new Actor in the Scene with the name of its first mandatory argument. If an Actor already exists in the scene with that name, it simply replaces it! This is necessary, because once an Actor is in a scene, it remains there until either the scene is changed, or the user removes it from the scene using Scene, Create Display List, and then Actors, Edit Actor to remove it.

Type that in the Script Window. Now, as before, click the Compile button at the bottom of the window. The Success! banner should appear. Click Ok. Then click Attach and Exit.

Finally, we create the script for the revolve Button. This button will cause the graph you have drawn to be revolved from the start angle to the stop angle (in degrees) and will then draw the surface of revolution thus swept out in yellow, drawing also the function at the start (in green) and also at the end (in red). Thus, click with the right mouse button anywhere on the revolve pushbutton. The menu should appear. Select from it Actions, then Edit Script. When you do this, the Script Window for revolve will appear. Type the following script in the window. Notice that each line ends with a semicolon.

let pt be evaluate(textlist("revs"));
if length(pt)==0 then { notice("Please enter a function.")} else {

make variable x;
make variable y;
let h(x) be value evaluate(text("revs"));
let f(x,y) be [0,0,0]; 'these red commands erase any previous graph'
let k(x) be [0,0,0];
let f1(x,y) be [0,0,0];
let f2(x,y) be [0,0,0];
set surfacerefinement to 5,5;
set curverefinement to 10;
surface f;
surface f1;
surface f2;
tube k;

let g(x,y) be [x,h(x)*cos(y),h(x)*sin(y)]; 'surface to sweep'
let domx1 be evaluate(text("domx11"));
let domx2 be evaluate(text("domx12"));
let domy1 be radian(evaluate(text("ang1")));
let domy2 be radian(evaluate(text("ang2")));
set the surfacerefinement to 40, 40;

'this loop draws the surface in incremental increases of 0.1'
do
i=domy1+.01
until i > domy2 {
let domy be i;
set the surfacedomain to [domx1+0.01, domx2-0.01], [domy1, domy];
draw the surface g using color yellow; 'draws next surface'

'this step guarantees the surface is drawn immediately'
gldraw {
flush();
}


i := i+.1;
}



let f1(x,y) be [x,h(x)*y*cos(domy1),h(x)*y*sin(domy1)]; 'start surface'
set the surfacerefinement to 30, 30;
set the curverefinement to 200;
set the surfacedomain to [domx1+0.01, domx2-0.01], [0, 1];
set the curvedomain to domx1, domx2;
draw the surface f1 using color lgreen; 'draw the start surface'
let f2(x,y) be [x,h(x)*y*cos(domy2),h(x)*y*sin(domy2)]; 'end surface'
draw the surface f2 using color lred; 'draw the end surface'
let k1(x) be [x, h(x)*cos(domy1),h(x)*sin(domy1)]; 'start curve'
let k2(x) be [x, h(x)*cos(domy2),h(x)*sin(domy2)]; 'end curve'
draw the tube k1 using color green width 0.2; 'draw the start curve'
draw the tube k2 using color red width 0.2; 'draw the end curve'

}

The red section of the script erases previous tubes and surfaces. Next, let g(x,y) be [x,h(x)*cos(y),h(x)*sin(y)]; defines the (yellow) surface that will be swept out in small increments, so that you can watch it grow, in the loop:

do
i=domy1+.01
until i > domy2 {
let domy be i;
set the surfacedomain to [domx1+0.01, domx2-0.01], [domy1, domy];
draw the surface g using color yellow; 'draws next surface'

'this step guarantees the surface is drawn immediately'
gldraw {
flush();
}


i := i+.1;
}

Notice the gldraw protocol. It makes a direct call to OpenGL to "flush" the buffers so that at each step the new slightly larger surface is drawn. Otherwise, OpenGL might draw the entire surface at the last stage only, and you would not see the "sweeping" effect.

The last steps simply draw the start curve and its surface in green, and the end curve and its surface in red.

Type that in the Script Window. Now, as before, click the Compile button at the bottom of the window. The Success! banner should appear. Click Ok. Then click Attach and Exit.

The revolutions Microworld is complete. Save the Document by selecting WorkBook, Save, as before. Now enter Reader Mode and try it out. When you are satisfied, close Mathwright by selecting WorkBook, then Exit from the menu.