GRASS (programming Language) - Example

Example

SINCURVE=[PROMPT "WHAT IS THE OFFSET?" INPUT OFFSET x=-160 angle=0 POINT OFFSET+x,SIN(angle)*80,3 angle=angle+2 IF (x=x+1)<159,SKIP -2]

This text creates a new macro called SINCURVE that can be called simply by typing SINCURVE into the command prompt, or from other macros or programs. SINCURVE uses two local variables, x and angle, as well as a global variable, OFFSET.

The PROMPT/INPUT is a modification of the original BASIC INPUT, which will not ask for the input if the user types it into the command line when calling the macro. In this case typing SINCURVE will result in the prompt appearing and the program waiting for input, whereas typing SINCURVE 30 will skip the prompt and OFFSET will automatically be assigned 30. This allows a single macro to be used both interactively and within a program as a function.

POINT is an example of one of the many graphics commands included in the Zgrass language. POINT requires an X and Y location, as well as a color. In this example the user supplied OFFSET moves the x position of the curve on the screen, while the Y position is supplied by the trig function, suitably enlarged for display (in this case, 80 times). The color is supplied in the last input, and in this case is 3. The UV-1 used color registers, so 3 did not imply a particular color, but a color selected from the current palette.

The IF is likewise interesting. It places an increment, (x=x+1), in front of the test, a feature not normally available in BASIC. In this case the IF is told to call SKIP -2 if true, which will move back two lines and can be used in place of a GOTO.

Read more about this topic:  GRASS (programming Language)

Famous quotes containing the word example:

    Our intellect is not the most subtle, the most powerful, the most appropriate, instrument for revealing the truth. It is life that, little by little, example by example, permits us to see that what is most important to our heart, or to our mind, is learned not by reasoning but through other agencies. Then it is that the intellect, observing their superiority, abdicates its control to them upon reasoned grounds and agrees to become their collaborator and lackey.
    Marcel Proust (1871–1922)