Scripting Tool For Goetz's Graphics Kit

Goetz's Graphics Kit has no method of making a loop. However, I 've made this free scripting tool for you to use in JavaScript, to create a loop that will write out the commands. This way if you have objects that you want to move across the screen, you don't have to write every step. You can write a loop that creates the steps in the animation.

This scripting tool works in Netscape or IE. However when using IE, pasting the text into Notepad it didn't look correct. Use Wordpad or another text editor.

Open up the file script.html in a text editor, and you'll find the function doCommands. In there is a comment saying to enter in your commands here. Place your commands there. You'll need to save a new html version of your script, because the script.html you use has some built in functions. Just save it as a new file name.

You give commands to be generated as:

command("text")

Where "text" is some command to be executed. You do need to place your commands in " ".

You'll have variables that change to reflect the object's size and/or position on the screen.

Here is an example script that has text zoom in and out. The script was generated using the following page which contains the code to create the script. This is the script file that is generated for the applet. However to create that script required only to create 2 functions, one for zooming in, the other for zooming out. The functions created the script. Here is the code that was used to make the script. That code will make more sense to you after you read the documentation on how to write functions, loops, and use variables.

A variable lets you store information in the memory of the computer. For example:

var x=100

var is a keyword that tells JavaScript you are setting up a variable in memory. The variable name in this case is called x. The = assigns x a value. The value assigned in 100. Variables can not have spaces in them, and they are case sensitive. So cat is different than CAT.

When you use the variable in the command, you need to use the + operator. For example:

var x=100
var y=150

command("textdisplay "+x+" "+y+" 24")

The + sign means concatenate, or join, the statements together to form one big string of text. The " " inbetween the statements leaves a space between them. The reason that variables don't have " " around them, is because you want the value of the variable, not the name of the variable. So the resulting command of that line is:

textdisplay 100 150 24

Now you can use a loop to change the x and y locations of the variable to display something at various locations on the screen.

If you want to have a piece of code done more than once, you can use a for loop.

Here is an example:

for(i=1;i<=10;i++) {

}

This will do something inside the {} 10 times. i is a variable that starts out equal to 1. Each time it's checked to see if i<=10 (if i less than or equal to 10). If that is true you keep doing the instructions in the {}. Each time you finish the instructions in the {}, i increments. The first time it checks the loop condition i=1, i<=10 so it goes through the loop once. At the end of the loop i is incremented to become 2. The loop is checked again and i<=10 so it goes again. The last time checking the loop i=10 and it goes through the loop. When the loop gets to the end, i becomes 11, but 11 is not less than or equal to 10 so the loop exits.

As you go through the loop, you can change the position of objects, by changing the variables.

x+=5 adds 5 to whatever x was equal to. You can also have:
x-=5 subtracts 5 from x.
x/=5 x becomes whatever x divided by 5 is.
x%=5 x becomes the remainder of x divided by 5.
x*=5 x becomes x times 5.

An example from before could be:

var x=10
var y=30

command("loop")
command("textset Lawrence Goetz")

for(i=1;i<=10;i++) {

        command("clear white")       
        command("textdisplay "+x+" "+y+" 24")
        command("pause 50")
       

        x+=10
        y+=5

}

You can also make functions too. This defines a function called text.

function text() {

}

To access it, you do:

text()

It will do whatever code is in between the {} and then return. You can setup a function to take a variable and insert it in some commands.

function move(text) {

        var x=10
        var y=30

        command("loop")
        command("textset "+text)

        for(i=1;i<=10;i++) {

                command("clear white")       
                command("textdisplay "+x+" "+y+" 24")
                command("pause 50")
       

                x+=10
                y+=5

         }

}

Now I can call it by doing, for example:

move("Lawrence Goetz")

You can pass more than one kind of variable to a function.

function move(text, x1, y1) {

        var x=x1
        var y=y1

        command("loop")
        command("textset "+text)

        for(i=1;i<=10;i++) {

                command("clear white")       
                command("textdisplay "+x+" "+y+" 24")
                command("pause 50")
       

                x+=10
                y+=5

         }

}

Now I can call it by doing, for example:

move("Lawrence Goetz",10,15)

When writing functions, they must not be inside another function. You have to write the code for your functions in another area outside the doCommands function area. Function names are also case sensitive, and can not include a space.

After you have made your script, open your html file in your browser and press the Generate button. When it's done, the text will be highlighted. Now you can cut and paste the text into your script file and use it as your animation script.


Questions or comments, e-mail me.

Visit my web site for other software I've made.