For general information and language reference about GeoScript, see the GeoScript Manual.
Contents:
Chapter 1: A simple triangle
Chapter 2: Basic drawings with lines
Chapter 3: Marking objects
Chapter 4: Circles
Chapter 5: Notable lines in a triangle; Text output
Chapter 6: Procedure "CONSTRUCTION"
Chapter 7: Animations
Chapter 8: "INTERACTION" procedure
Chapter 9: Limiting movements in animations and
interactions
Chapter 10: A menu
Chapter 11: Changing default styles and colors
Chapter 1: A simple
triangle
(Introducing POINT, LINE, WAIT, END)
Let us start with a very basic construction: a triangle. This is the program which accomplishes this:
POINT A, 100,360 'This point receives the default properties. POINT B, 400,360, 2,(255,0,0) 'Style 2, red, default thickness. POINT C, 300,85, DEFAULT, DEFAULT, 40 'Thickness 40. a = LINE B,C 'This line receives the default properties. b = LINE A,C, &HF0F, (0,0,255) 'dashed line, blue, default thickness. c = LINE A,B, &H101, DEFAULT, 5 'dotted line, thickness 5. WAIT 'Let user press a button before program exits. END |
The parts after single quotation marks ' are comments. The ' indicates that what follows should not be interpreted as a program instruction. The GeoScript interpreter treats such comments as if they were simply not there.
First we initialize three points on the screen. This is done with the instruction POINT, which has the following syntax:
POINT name, x, y [, style, color, thickness]
name can be any name you choose, except a GeoScript
keyword. So you cannot name your point "point", for
example. (You cannot name it "line" either; but I
suppose you won't do this anyway.) x and y are
the coordinates of the point on the screen.
If you have used any other programming language before, you know
that programming languages use variables to store data like
numbers, text strings, etc. In order to assign a numerical value
to a variable, you would write something like: a = 5,
where "a" is the name of the variable which receives
the value 5.
This is exactly what the instruction POINT does. "A"
(in the example script) is the name of a variable - in this case
a point - , and the coordinate pair "100,360" is the
value we assign to A.
But GeoScript is unique in the sense that it has no numerical
variables. Since it is a language for geometry programs, its
variables represent geometrical objects. There are three data
types (i.e. types of variables) in GeoScript: points, straight
lines and circles. (For an overview of these types and their
properties, see the corresponding section in the GeoScript Manual.)
A name and a pair of coordinates is everything we need in order to initialize a point. Note that screen coordinates are "upside down": the y-value increases from the top towards the bottom. - However, there are three additional values which are optional:
- style defines the way a point is shown on the
screen. If you do not specify style, the point is shown
as a thin cross. Point B in our example is shown as a filled
circle (style 2).
- color is a RGB triplet (red, green, blue). Each of the
three components can assume a value from 0 (dark) to 255 (maximum
intensity). If you do not specify color, the point is
drawn black. By the way, color values are the only expressions in
GeoScript which use brackets.
- thickness is the size of the point how it is drawn on
the screen. For the default style, it indicates the length of the
crossed lines in pixels. For style 2, it indicates the diameter
of the circle.
(For a complete explanation of styles and appearances, see
the corresponding section in the GeoScript Manual.)
If you want to specify only thickness, but leave style and color in their default state, you can write DEFAULT in the place of these parameters, as in the third line of the above example:
POINT C, 300,85, DEFAULT, DEFAULT, 40
Passing the value -1 has the same meaning as DEFAULT.
When you run this script, you will note that the points appear
one by one on the screen, with a wait time of two seconds between
each point. You can skip these wait times by pressing any key.
(Later on we will see ways to put constructions immediately on
the screen, when we discuss CONSTRUCTION procedures.)
For more details about the user interface of GeoScript, see
the section "Screen
Layout" of the GeoScript Manual.
- Next, we unite the points with straight lines. This is accomplished with the instruction LINE. Its syntax is:
line = LINE point1, point2 [, pattern, color, thickness]
You will notice a difference between the form
of this instruction and the former. In "POINT name ..."
we have first the keyword and then the variable name. Here we
have first the variable name and then the keyword. (The
"=" sign is optional.) The first form is the form of an
initialization instruction, where we define the type of a
variable and assign numerical values to it (such as coordinates).
The form we have here, is a geometrical operation (or
construction), where we use one or more already existing
element(s) (two points, in this case) to create one or more new
element(s) (a line, in this case).
The instruction LINE exists also as initialization instruction,
in the following form:
LINE name, x1, y1, x2, y2 [, pattern, color, thickness]
Here, x1,y1 and x2,y2 are the coordinates of
two points which define the line.
So, instead of doing it as in the example, we could also
construct our triangle by initializing three lines and then
calculating the points where they intersect. But it is more
practical to do it the way we do it in our example.
You will notice also that we have points named A,B,C and lines
named a,b,c. This is not a problem, since GeoScript
differentiates between uppercase and lowercase letters; so A
is not the same as a. But this means
that you must type carefully: if you name for example a point Top
and later refer to it as top, you will
get an error.
Keywords, on the other hand, are not case sensitive: instead of LINE,
we could also write line, Line,
or even lInE.
As with POINT, the instruction LINE has its optional parameters which are explained in this section of the GeoScript Manual.
To run the script (under Windows), run "GeoScript.exe", and in the appearing dialog box select the script file you want to run ("tutorial1.geo" in this case). You can also open Windows Explorer in the folder where your script file reside, and drag it onto the GeoScript icon.
This is the output of our program:
- There are two last instructions to explain:
WAIT stops program execution until the user clicks on a button or presses one of the predefined keys. Without this instruction, the program window would close immediately after the triangle is finished, and we would not have time to admire the result of our first program.
END ends the program - there is nothing more to say about it. End.
Chapter 2: Basic drawings
with lines
(Introducing LINEPOLAR, CROSS, STARTLINE, ADVANCETO)
In Chapter 1 we got acquainted with the geometrical construction LINE. Now we will add some more constructions to our first program:
hc = LINEPOLAR C, c, 90º, &HF0F
The instruction LINEPOLAR draws a line which passes through a given point and forms a specified angle with a given line. Angles are specified in degrees and increase counterclockwise. (The degree sign º after the number is optional; but it makes your script better understandable. In case you revise it fifty years later when you will have forgotten what everything means.)
Here we use LINEPOLAR in order to draw a right angle to the base c, passing through the point C; this is, the height of the triangle. The Pattern value &HF0F produces a dashed line.
There is also an initialization instruction LINEPOLAR of the following form:
LINEPOLAR name, x1, y1, angle [, pattern, color, thickness]
Here x1,y1 are the coordinates of the origin of the line, and angle is an absolute angle: 0º means a line pointing to the right, 90º upwards, 180º to the left, etc. You will remember this easily when you remember that GeoScript follows Christian principles: First you decide to do what is right; then you lift your eyes up to get help from the Most High.
- Next, we draw the height through point B in the same way:
hb = LINEPOLAR B, b, 90º, &HF0F
Then we store the crosspoint of the two heights in a variable H:
H = CROSS hc, hb, 4, &HFF0000
The number 4 is a point style, it causes the point to be drawn
as a filled square. &HFF0000 is a color value and means
intense red. - In Chapter 1 we saw another form of specifying
colors; in that form you would write (255,0,0). Instead of that,
you can use this hexadecimal form &HRRGGBB (two digits for
Red, two for Green and two for Blue). But if hexadecimal numbers
make your stomach ache, you will of course prefer the bracketed
form (red, green, blue).
Not very important note:
This form of writing hexadecimal numbers corresponds to the
syntax of the family of programming languages BASIC, in which
GeoScript was written. For color values, also 0xFF0000 and
0FF0000h are acceptable. However, these latter forms are not
accepted for line patterns and for other values you may wish to
express in hexadecimal. (You can express also coordinates,
angles, etc. in hexadecimal if this makes you happy; but then you
MUST use the prefix &H.)
Next, just for examples' sake, we initialize another point and line with the following instructions:
POINT X, 400, 280, -1, (0,128,0) x, Y = STARTLINE X, 0º, 180, -1, (0,128,0), 3
The instruction STARTLINE serves mainly educational purposes:
it initializes a line exactly the way you would draw a new line
of given length on paper. It takes a point you have already
drawn, draws a straight line from there in a certain direction
(0º = to the right in this example), and measures the desired
length (180 pixels, in this example) from the startpoint. The
last three parameters are the graphical properties of the line:
default pattern, color green and thickness 3.
The general syntax of STARTLINE is:
line, point2 = STARTLINE point, angle, distance [, pattern, color, thickness]
You see that this instruction has two results: a line and a point (the endpoint). The endpoint will have the same graphical properties as the startpoint.
Now we want to define a third point on this line x, at a distance of 50 pixels from X towards Y. This is achieved with the following instruction:
Z = ADVANCETO X, Y, 50, 2
(The last parameter, 2, is the style of the new
point Z.)
If we have already a line constructed from X to Y, as in this
example, we could achieve the same result with the following
instruction:
Z = ADVANCEON X, x, 50, 2
The only difference between ADVANCETO and ADVANCEON is that ADVANCETO takes as parameters two points, and ADVANCEON takes a point and a line.
Now, if we use ADVANCEON, the question is: in which direction will we advance? Since a line goes in two directions, what if GeoScript makes a mistake and advances to the left, when we want to advance to the right? - The answer is found in the vectorial format GeoScript uses internally. For a line, it stores not only its location, but also its direction. This direction depends on the way the line was initially constructed. In our case, we constructed it using an absolute angle; so we can be sure the line points to the right, not to the left. For a line constructed by uniting two points, its vector points from the first point toward the second, and not in reverse order.
As a last example, we will construct a line starting at Z in an angle of 30 degrees:
z = LINEPOLAR Z, x, 30º, -1, (0,128,0), 3
Here we can ask again: in which direction will this angle point? To the right or to the left? - Again we have a look at the line's vector, and remember that angles increase counterclockwise. So there is only one answer: this line will point upwards to the right.
This is the whole program:
POINT A, 100,360, -1, &H0000FF POINT B, 400,360, -1, &H0000FF POINT C, 300,85, -1, &H0000FF a = LINE B,C b = LINE A,C c = LINE A,B hc = LINEPOLAR C, c, 90º, &HF0F 'dashed line hb = LINEPOLAR B, b, 90º, &HF0F H = CROSS hc, hb, 4, &HFF0000 POINT X, 400, 280, -1, (0,128,0) x, Y = STARTLINE X, 0º, 180, -1, (0,128,0), 3 'A green line 3 pixels thick. Z = ADVANCETO X, Y, 50, 2 'A point at 50 pixels from X towards Y. z = LINEPOLAR Z, x, 30º, -1, (0,128,0), 3 WAIT END |
And this is its output:
Chapter 3: Marking objects
(Introducing MARKPOINT, MARKLINE, MARKANGLE, MARKNUMBERANGLE,
MARKNUMBERLINE.)
We will still use the program from the previous chapter, and make some more additions to it. Since our points and lines have names, it would be nice to see these names also on the screen. This is done with the MARK... family of instructions. To mark a point, we use:
MARKPOINT point [, size, position]
size is an optional parameter which
indicates the letter size (height) in pixels. If you omit it, the
default size of 16 pixels applies.
position indicates where exactly you want to place the
label of your point. When you draw on paper, you can easily see
where you can write a letter outside from interferring lines; but
GeoScript is not that smart. If you do not indicate where exactly
to put the letter(s), it will label a point always on top of it.
For the points A and B of our triangle, this would not look nice,
since the letters would be crossed by the lines a and b,
respectively. Therefore, we indicate with a value of 2 that we
want the letter to be placed below the point:
MARKPOINT A, -1, 2 MARKPOINT B, -1, 2
(For more position values and other details about the marking instructions, see the GeoScript Manual.)
For point C, the default position is OK. But as an example, we will use a larger letter size here:
MARKPOINT C, 24
For marking a line, there are two alternate forms:
MARKLINE line [, point1, point2, size, position]
MARKLINE line [, size , position]
You must in some way indicate where along the
line the label should be placed. You can specify two points on
the line, and the label will be placed in the middle between
them. Be careful, GeoScript does not check if these points are
actually on the line. If they are not, you may get some weird
results.
If you do not specify any points, the label will be drawn in the
middle between the origin of the line (the startpoint from which
it was originally constructed) and the endpoint of its vector
starting from there. (In Chapter 2 we have shortly explained line
vectors.) For our triangle this is OK, since we constructed the
lines from the endpoints of the triangle; so we will not specify
any points:
MARKLINE a, -1, 1 MARKLINE b MARKLINE c, -1, 1
You see that we change the position value for lines a and c, since we prefer to have all labels outside the triangle. For lines, there are only two position values: the default is left of the line, if the line is steeply inclined (over 45º), and on top of the line if it is rather flat. A value of 1 changes the position to the right resp. below the line.
Now for the angles. The two forms of the marking instruction are:
MARKANGLE line1, line2, "text" [, size, position, radius]
MARKANGLE point1, point2, point3, "text" [, size, radius]
Since angles are not stored in variables, they
have no names, and we must give them one now. That is what the
parameter "text" is for. You must enclose this
text within double quotation marks "". - In addition to
the label, angles will also be marked with an arc. You can
specify the size of this arc in the optional paramenter
radius.
In the first form of the instruction, the angle is defined by two
lines. But this is not sufficient, since there are at least four
different angles (even more) which could be marked between two
lines:
I began numbering these possibilities with 0,
because this is a programmer's custom (very useful for dealing
with computers, but not for everyday life). And also because
these red numbers correspond to the optional parameter position.
Position 0 (default) is the angle counterclockwise from line1
to line2, position 1 is the next angle following in
counterclockwise direction, etc.
But this is not all yet. The vector of line2 could point
in the opposite direction, and which one of the following is then
the angle counterclockwise from line1 to line2
?
As you see, position 0 will always choose the smaller angle (<180º), regardless of the direction of line2. Position 4, on the other hand, will always mark exactly the angle from vector 1 to vector 2, even if it is greater than 180º. |
So, if you are not careful, this instruction may easily mark a different angle from the one you want. Therefore, wherever you have three known points which define an angle, you should use the second form of the MARKANGLE instruction. This form needs no position parameter, since it will always turn counterclockwise from point1 to point3, with point2 as the origin of the angle, as shown to the right: |
This is what we do in our example script:
MARKANGLE B,A,C, "a" MARKANGLE C,B,A, "b" MARKANGLE A,C,B, "g", 24, 150
You will see that the screen output is with greek letters: instead of a latin "a", a greek alpha will appear. Gamma is represented by "g", not "c". - With this third angle, we use a larger font size (24) and a larger arc radius (150 pixels).
Marking sizes of angles and lines
Sometimes it is desirable to not only indicate the name of an angle, but also its size. You do this with the instruction MARKNUMBERANGLE, which has exactly the same syntax as MARKANGLE (both forms), but will additionally calculate and display the size of the angle in degrees. In our example script, we will indicate the size of the angle between height hc and baseline c, which should be 90º:
MARKNUMBERANGLE c, hc, "f"
For lines, you use MARKNUMBERLINE, which has the following syntax:
MARKNUMBERLINE line [, point1, point2, factor, size, position]
This instruction will indicate the distance
between point1 and point2 in pixels; or if no
points are given, the length of the vector of the line.
You see here an additional optional parameter, factor.
This is an integer number by which the pixel value will be
divided. So you can define your own measuring unit; for example
with a factor of 10, a distance of 10 pixels will be labelled as
1, 50 pixels as 5, etc.
This is the complete program:
POINT A, 100,360, -1, &H0000FF MARKPOINT A, -1, 2 'Default Font Size; Position 2 = bottom. POINT B, 400,360, -1, &H0000FF MARKPOINT B, -1, 2 POINT C, 300,85, -1, &H0000FF MARKPOINT C, 24 'Use a larger font size here. a = LINE B,C MARKLINE a, -1, 1 'Position: Right-Bottom b = LINE A,C MARKLINE b c = LINE A,B MARKLINE c, -1, 1 'Position: Right-Bottom 'Mark the angles of the triangle: MARKANGLE B,A,C, "a" MARKANGLE C,B,A, "b" MARKANGLE A,C,B, "g", 24, 150 'Larger font size and arc radius. hc = LINEPOLAR C, c, 90º, &HF0F MARKNUMBERANGLE c, hc, "f" hb = LINEPOLAR B, b, 90º, &HF0F H = CROSS hc, hb, 4, &HFF0000 POINT X, 400, 280, -1, (0,128,0) x, Y = STARTLINE X, 0º, 180, -1, (0,128,0), 3 Z = ADVANCETO X, Y, 50, 2 MARKNUMBERLINE x, X,Z 'Mark distance X-Z. z = LINEPOLAR Z, x, 30º, -1, (0,128,0), 3 WAIT END |
And here the screen output:
Chapter 4: Circles
(Introducing CIRCLE, CROSS with circles, TANGENT.)
Like POINT, LINE and LINEPOLAR, the instruction CIRCLE has also two uses. To initialize a circle with numerical values, its syntax is:
CIRCLE name, x, y, radius [, color, thickness, start, end]
x,y are the coordinates of the circle center. The optional parameters start and end indicate the start and end angle of the arc, in degrees; so they allow to draw only an arc instead of a full circle. - These properties apply only to the way the circle is drawn on the screen, but not to constructions: If you construct, for example, the crosspoints of a circle with a line, these points will be created even if they are located on the invisible part of the arc.
As a construction, CIRCLE has the following two forms:
circle = CIRCLE center, point [, color, thickness, start, end]
circle = CIRCLE center, line [, color, thickness, start, end]
In the first form, the circle will pass through
point. In the second form, the circle will be tangential
to line.
The following sample program uses all three variants of the
CIRCLE instruction:
CIRCLE c1, 200,200, 150, (128,128,0), 3 POINT C, 280,280 MARKPOINT C POINT A, 460,370 MARKPOINT A c2 = CIRCLE C, A, (128,128,0), 3 'CIRCLE with two points: C is the center, and the circle passes through A. LINEPOLAR t, 20,410, 0º c3 = CIRCLE A, t, (255,0,0), 1 'CIRCLE with a point and a line: A is the center, and t is a tangent. 'Crosspoints between a circle and a line: P,Q = CROSS t, c2 MARKPOINT P MARKPOINT Q 'Crosspoints between two circles: R,S = CROSS c1, c2 MARKPOINT R MARKPOINT S a,b = TANGENT P, c1, &HF01, (0,160,0) WAIT END |
You see here also two new variants of the CROSS instruction:
P,Q = CROSS t, c2 R,S = CROSS c1, c2
In the first case, the crosspoints of a line with a circle are
constructed; in the second case, the crosspoints of two circles.
Since there may be two crosspoints, you must put the results in
two different variables.
But what if there is only one crosspoint (in the case of a
tangent), or none at all? - In this case, GeoScript will simply
declare the points P and Q (resp. R and S) as "invalid"
and will not show them on the screen. No error will interrupt
your program; but if you use such invalid points in further
constructions (for example, uniting them with a line), the
results will also be invalid.
(Note: No, actually in the case of a
tangent it resulted more meaningful not to declare any crosspoint
as invalid, but to assign to both the same value. The current
version of GeoScript should work this way.)
The last instruction to explain is:
a,b = TANGENT P, c1, &HF01, (0,160,0)
This draws the tangents (again two variables for the possible results) from point P to circle c1. Of the usual optional parameters (pattern, color, thickness), two are given: &HF01 draws a dash-dot line, and its color is green.
Here is the output of the program:
There are two gray elements on the screen you might not have
expected: a perpendicular line from A to the line PQ, and a
circle passing through P and through the center of circle c1.
These are auxiliary lines you would also draw on paper if you
would realize these constructions exactly: they help to find the
exact points where the circle touches its tangent.
Of course, the computer has no need of these auxiliary lines for
calculating circles and tangents. They are being drawn purely for
educational purposes. (Later on we will see how we can realize
constructions in FAST mode, where these auxiliary elements will
not appear.)
Chapter 5: Notable lines in
a triangle; Text output
(Introducing MIDDLE, MIDLINE, BISECTOR, REVERT; SCREEN,
WINDOW, TEXTWINDOW, TEXT, CLS)
When showing geometrical constructions with GeoScript, it would be good to put some text on the screen in order to explain to the user what we are doing. There is a series of screen instructions which accomplish this. For text output, you need the following instructions:
TEXTWINDOW x, y, width, height
TEXT "text" [, fgColor, bgColor, size]
Instead of TEXTWINDOW, you can also write TWINDOW. This
instruction defines a rectangle within the window where text will
appear. You cannot use the TEXT instruction without specifying a
TEXTWINDOW somewhere earlier in the program.
The "text" to display must be enclosed in double
quotation marks "" and must remain on the same line in
the script. (GeoScript handles line wrapping - although not
perfectly - to fit the text inside the TEXTWINDOW.)
The meaning of the optional parameters is: fgColor =
color with which the text will be drawn. bgColor =
background color with which the text window will be filled. size
= letter height in pixels.
So, we put a TEXTWINDOW and a TEXT instruction somewhere
between the construction instructions of the former example. What
happens? The text will appear only for a short moment. You may
not even be able to see it. As soon as the next element is drawn,
the text disappears. This is because the TEXTWINDOW is inside the
area where graphics are drawn, so it will be covered as soon as
graphics are updated.
There are two ways to avoid this:
- Pause program execution with WAIT if a text has to be shown in
the middle of a construction.
- Restrict the graphics output area so it does no longer
interfere with the text window.
In our example program, we will use the second approach. Look at these lines:
SCREEN 600,460 WINDOW 600, 380 TWINDOW 2,380, 596,60
The instruction SCREEN defines the size of the application
window (here 600x460 pixels). If you omit this instruction (as in
the former examples), the window will be initialized to the
default size of 640x480.
The instruction WINDOW defines the size of the area where
graphics are displayed. This area will be clipped to the right
and at the bottom if it is smaller than the application window.
So in our example, graphics will fill the whole 600 pixels of the
window's width, but only 380 of its height, so 460-380=80 pixels
will be left free at the bottom for text.
Therefore, our text window begins at the y-coordinate 380 and has
a height of 60 pixels. (Take into account that the lowest 20
pixels are occupied by the default buttons. They will cover text
that is displayed there.)
You can of course change the size and location of the textwindow
during the program. But in our example here we will use the same
textwindow throughout the whole program.
After this initialization, we construct a triangle and mark its elements as in chapter 3. There is no need to repeat this code here. After that, we output some text in order to explain what we will do:
TEXT "We will join each point of the triangle with the middle of the opposite side. The resulting lines intersect in the gravity center of the triangle.", (0,0,255)
(Note that this whole text must actually be written on a single line. I am wrapping it here only so that you need not scroll the window to read it.)
Then we construct and mark the gravity center with the following lines:
D = MIDDLE B,C E = MIDDLE A,C F = MIDDLE A,B d = LINE A,D, -1, (0,0,255) e = LINE B,E, -1, (0,0,255) f = LINE C,F, -1, (0,0,255) G = CROSS d, e, -1, (0,0,255) MARKPOINT G
The instruction MIDDLE simply places a point exactly in the
middle between two other points. You can optionally specify the
style, color and thickness of the resulting point.
Now we want the user to actually see this picture; so we pause
the program with WAIT. But before that, we output some text to
inform the user what he should do now:
TEXT "Press Resume to continue.", (255,255,0), (160,0,0) WAIT
Next we construct the circumcircle of the triangle. We write again some text to explain, and then do the following construction:
h = MIDLINE B,C, -1, (255,0,0) i = MIDLINE A,C, -1, (255,0,0) j = MIDLINE A,B, -1, (255,0,0) M = CROSS h,i, -1, (255,0,0) MARKPOINT M c1 = CIRCLE M,A, (255,0,0)
The instruction MIDLINE draws a perpendicular line in the
middle between two points, and has the same optional parameters
as all construction instructions (pattern, color and thickness,
in the case of a line). You will see again appearing some
auxiliary lines which simulate the actual construction on paper.
Here is the result:
Now we have already quite a lot of lines on the screen, and
drawing more over it would look rather messy. Therefore, after a
WAIT, we clean the screen with the instruction CLS. You can
optionally specify a background color; for example CLS (0,0,100)
will fill the screen with a dark blue.
But now we have to draw our triangle again, so we have to copy
here the same set of instructions as in the beginning. After
that, we can do a new construction in the triangle. This time, we
construct its incircle:
d = BISECTOR c,b, -1, (0,190,0) REVERT c e = BISECTOR a,c, -1, (0,190,0) REVERT a REVERT b f = BISECTOR b,a, -1, (0,190,0)
M = CROSS d,e, -1, (0,190,0) c2 = CIRCLE M, a, (0,190,0)
The instruction BISECTOR draws the bisector of the angle
between two given lines. And what is the REVERT for? - This has
again to do with the direction of line vectors. As we discussed
in an earlier chapter, there are several ways to interpret what
the angle is between two lines; and likewise there are several
ways to construct a bisector between two lines. BISECTOR will
always use the angle counterclockwise from line1 to line2. If the
vectors of these lines do not point in the desired direction, we
must invert them with REVERT. This instruction changes nothing in
the location and appearance of a line; it simply turns its vector
in the opposite direction.
If you want to know what difference this makes, simply take out
the REVERT instructions (or convert them to comments by putting a
' before them), run the script again and watch.
There is a last part in this program which constructs the heights. There is nothing new in that part. Here is the complete program:
SCREEN 600,460 WINDOW 600, 380 TWINDOW 2,380, 596,60 POINT A = 70,340 POINT B = 530,340 POINT C = 140,40 c = LINE A,B b = LINE A,C a = LINE B,C MARKPOINT A, -1, 2 MARKPOINT B, -1, 2 MARKPOINT C MARKLINE a MARKLINE b MARKLINE c, -1, 1 TEXT "We will join each point of the triangle with the middle of the opposite side. The resulting lines intersect in the gravity center of the triangle.", (0,0,255) D = MIDDLE B,C E = MIDDLE A,C F = MIDDLE A,B d = LINE A,D, -1, (0,0,255) e = LINE B,E, -1, (0,0,255) f = LINE C,F, -1, (0,0,255) G = CROSS d, e, -1, (0,0,255) MARKPOINT G TEXT "Press Resume to continue.", (255,255,0), (160,0,0) WAIT TEXT "Now we will draw perpendicular lines from the middle points of each side. They intersect in the center of the circumcircle of the triangle.", (255,0,0) h = MIDLINE B,C, -1, (255,0,0) i = MIDLINE A,C, -1, (255,0,0) j = MIDLINE A,B, -1, (255,0,0) M = CROSS h,i, -1, (255,0,0) MARKPOINT M c1 = CIRCLE M,A, (255,0,0) TEXT "Press Resume to continue.", (255,255,0), (160,0,0) WAIT CLS 'Now we must draw the triangle again. c = LINE A,B b = LINE A,C a = LINE B,C MARKPOINT A, -1, 2 MARKPOINT B, -1, 2 MARKPOINT C MARKLINE a, -1, 1 MARKLINE b MARKLINE c, -1, 1 TEXT "We bisect each angle of the triangle. The crosspoint of the bisectors is the center of the inscribed circle.", (0,190,0) d = BISECTOR c,b, -1, (0,190,0) 'We must invert the vector of c, so that its origin is in B ' and the bisector will be drawn in the correct angle. REVERT c e = BISECTOR a,c, -1, (0,190,0) REVERT a REVERT b f = BISECTOR b,a, -1, (0,190,0) M = CROSS d,e, -1, (0,190,0) c2 = CIRCLE M, a, (0,190,0) TEXT "Press Resume to continue.", (255,255,0), (160,0,0) WAIT TEXT "The height of the triangle is a perpendicular line from a point to the opposite side. There are three heights and they intersect in a single point.", (160,0,160) hc = LINEPOLAR C,c, 90º, -1, (160,0,160) ha = LINEPOLAR A,a, 90º, -1, (160,0,160) hb = LINEPOLAR B,b, 90º, -1, (160,0,160) H = CROSS hc, ha, -1, (160,0,160) MARKPOINT H TEXT "Press Resume or Exit to end the program.", (255,255,0), (160,0,0) WAIT END |
And here is the output of the second half of the program:
Chapter 6: Procedure
"CONSTRUCTION"
(Introducing CONSTRUCTION, REPEAT, CALL / CONSTRUCT, FAST,
PACE, SLOW / TOOLS, IPOINT)
In the last example, we had to draw the same triangle twice. Instead of copying the same instructions again, there is a more convenient way to do this. We can put these instructions into a procedure (sometimes also called "subroutine") of the type CONSTRUCTION. Then we need only a single line to CALL this procedure. All the instructions contained in the procedure will execute, and then the program will continue normaly with the line following the instruction CALL.
Procedures must be placed after all other instructions (which are also called the "main module"). So, we place the following block of instructions at the end of our program:
CONSTRUCTION Triangle A,B,C c = LINE A,B b = LINE A,C a = LINE B,C MARKPOINT A, -1, 2 MARKPOINT B, -1, 2 MARKPOINT C MARKLINE a MARKLINE b MARKLINE c, -1, 1 REPEAT
The word CONSTRUCTION tells the GeoScript interpreter that a procedure of the type "CONSTRUCTION" begins here. "Triangle" is the name of the procedure. (Every procedure must have a name, because you must be able to CALL it by its name from another part of the program.) A,B,C are the parameters of the procedure.
Parameter passing is an important concept of programming. When
you CALL the procedure "Triangle", the procedure
expects you to give it three points to work with. They must not
necessarily be the points A,B,C of the main module; they can be
any points. You can for example write "CALL Triangle
D,E,F"; then the procedure will construct a triangle out of
the points D, E and F. Everywhere in the procedure where the
variable A appears, it will use D instead of A, and likewise E
instead of B and F instead of C.
You must make sure that you call the procedure with the correct
type of parameters. If you try, for example, "CALL Triangle
ha, hb, hc", you will get a "Type Mismatch Error",
because ha, hb and hc are defined as lines, not as points,
elsewhere in the program.
Inside a procedure, every variable which is not declared as a
parameter, is a global variable; i.e. it is the same variable as
the one with this name in the main module. So for example in the
above procedure, the lines a, b and c are global variables. When
you CALL Triangle, afterwards the lines a, b and c will have
changed. (Other programming languages use "local
variables" in their procedures. But there are no local
variables in GeoScript.)
On the other hand, the parameters A,B,C, as we already mentioned,
are not the same as A,B,C in the main
module. Suppose the procedure would change the values of
parameters A, B and C. When you "CALL Triangle D,E,F",
the points A,B,C will not change at all; but the points D,E,F
will.
Note that procedure names are case sensitive: if you "CALL
triangle", "Triangle" will not respond, because it
does not recognize its name in this form.
Every procedure ends with the instruction REPEAT. After REPEAT, you can optionally put a number, indicating how many times the procedure should repeat itself. So if you write REPEAT 5, the procedure will repeat itself five times before the program continues after CALL. If you omit the number, the procedure will execute only once and then return.
(There are no examples for repeated CONSTRUCTIONs in this tutorial. But you can find some in the other example scripts, for example in "Spiral.geo" and in "Conicals.geo").
Instead of CALL, when you call a CONSTRUCTION, you can also write CONSTRUCT.
Execution modes
There are three different modes with which you can call a procedure: SLOW, PACE and FAST.
PACE is the mode you have seen until now: Elements are drawn on the screen one by one, with a delay of two seconds after each. (Although the user can skip these wait times by pressing any key except "R", [Esc] and [PageUp].) If you do not specify a mode, CONSTRUCTIONs will execute in this mode. The main module executes always in PACE mode.
FAST mode draws the whole CONSTRUCTION at once, as fast as your machine's performance allows.
SLOW mode is for educational animations. It shows not only the
geometrical elements, but also a simple animation of the tools
with which you would draw them on paper (ruler, compass, etc).
This takes time of course, but is fun to watch especially for
beginners. - Instead of SLOW you can also write TOOLS.
Here is part of such a tool animation from the sample script
below:
In a CALL instruction, the mode keyword must be placed after the procedure name, but before the parameters. For example:
CALL Triangle FAST, X, Y, Z
The following sample program shows examples for all three modes. It is essentially the same as in the previous chapter. But since we are practicing procedures, the other constructions (gravity center, circumcircle, etc.) are also placed in procedures and CALLed from the main module. And you will see that the triangle is initialized to other points in the middle of the program.
- There is another change in this program: When initializing points A,B,C, you see that instead of POINT we use the instruction IPOINT. The "I" stands for "Invisible". Points initialized with IPOINT will not appear on the screen and will therefore not consume any wait time either. (You may already have got bored by the slow appearance of the three points on the screen in the previous examples.) - You can still later on in the program mark points initialized with IPOINT.
Likewise you can prefix almost all initialization and construction instructions with an "I": ILINE, ICIRCLE, ICROSS, IMIDLINE, etc.
SCREEN 600,460 WINDOW 600, 380 TWINDOW 2,380, 596,60 IPOINT A = 70,340 IPOINT B = 530,340 IPOINT C = 140,40 TEXT "Triangle construction in PACE mode. This is the default." CALL Triangle PACE A,B,C TEXT "Gravicenter construction in FAST mode. Press Resume to continue." CALL Gravicenter FAST A,B,C WAIT 'Clear Screen and draw triangle again: CLS CALL Triangle FAST A,B,C TEXT "Circumcircle construction in SLOW mode." CALL Circumcircle SLOW A,B,C CLS TEXT "Incircle construction in default mode (PACE)." 'Now we initialize our triangle to other points: POINT X, 100,80, 3,(0,160,0) POINT Y, 400,80, 3,(0,160,0) POINT Z, 250,300, 3,(0,160,0) 'No need to call "Triangle" here: "Incircle" draws the lines. CALL Incircle X,Y,Z WAIT 4000 'Wait for 4 seconds. CLS TEXT "Height construction in SLOW mode." Markpoint X Markpoint Y Markpoint Z 'No need to call "Triangle" here: "Heights" draws the lines. CONSTRUCT Heights SLOW X,Y,Z TEXT "Press Resume or Exit to end the program.", (255,255,0), (160,0,0) WAIT END ' Main module ends here. Procedures begin here. CONSTRUCTION Triangle A,B,C c = LINE A,B b = LINE A,C a = LINE B,C MARKPOINT A, -1, 2 MARKPOINT B, -1, 2 MARKPOINT C MARKLINE a MARKLINE b MARKLINE c, -1, 1 REPEAT CONSTRUCTION Gravicenter A,B,C D = MIDDLE B,C E = MIDDLE A,C F = MIDDLE A,B d = LINE A,D, -1, (0,0,255) e = LINE B,E, -1, (0,0,255) f = LINE C,F, -1, (0,0,255) G = CROSS d, e, -1, (0,0,255) MARKPOINT G REPEAT CONSTRUCTION Circumcircle A,B,C h = MIDLINE B,C, -1, (255,0,0) i = MIDLINE A,C, -1, (255,0,0) j = MIDLINE A,B, -1, (255,0,0) M = CROSS h,i, -1, (255,0,0) MARKPOINT M c1 = CIRCLE M,A, (255,0,0) REPEAT CONSTRUCTION Incircle A,B,C c = LINE A,B b = LINE A,C a = LINE B,C d = BISECTOR c,b, -1, (0,190,0) REVERT c e = BISECTOR a,c, -1, (0,190,0) REVERT a REVERT b f = BISECTOR b,a, -1, (0,190,0) M = CROSS d,e, -1, (0,190,0) c2 = CIRCLE M, a, (0,190,0) REPEAT CONSTRUCTION Heights A,B,C c = LINE A,B b = LINE A,C a = LINE B,C hc = LINEPOLAR C,c, 90º, -1, (160,0,160) ha = LINEPOLAR A,a, 90º, -1, (160,0,160) hb = LINEPOLAR B,b, 90º, -1, (160,0,160) H = CROSS hc, ha, -1, (160,0,160) MARKPOINT H REPEAT |
Chapter 7: Animations
(Introducing ANIMATION, STEP, TRACE)
In the previous chapter we have seen procedures of the type CONSTRUCTION. There are two other types of procedures. One of them is ANIMATION. It allows repeating the same constructions many times, while the starting points are moving. In FAST mode, this gives the impression of a geometrical figure changing its shape constantly.
The following example uses the CONSTRUCTIONs "Triangle" and "Circumcircle", which we know already from the previous chapter. But now these two procedures are called from inside another procedure of the type ANIMATION, which looks as follows:
ANIMATION Circum STEP A, 4,-1 TRACE M CALL Triangle FAST A,B,C CALL Circumcircle FAST A,B,C REPEAT 150
First we have the keyword ANIMATION and the procedure name. Animations cannot take parameters. - Then we find two new instructions:
STEP A, 4,-1
The STEP instruction indicates that the point A will be moving
during the animation. The numbers are the amount of pixels the
point will move after each repetition: 4 pixels to the right and
1 pixel upwards.
Actually you can "STEP" not only points, but also
circles (but not lines). Consult the GeoScript
Manual.
TRACE M
The TRACE instruction indicates that the point M will be "traced" during the animation. This means that while the other elements are deleted and recreated anew at each repetition, point M will leave behind a "trace" of all its positions since the beginning of the animation. - After TRACE, you can specifiy several points on the same line (up to 14).
Instructions STEP and TRACE apply generally to the whole procedure, no matter where in the procedure they are placed.
- After these, we CALL our constructions "Triangle"
and "Circumcircle". Note that ANIMATIONs can call other
procedures, but CONSTRUCTIONs cannot call any other procedure.
(Note: This is slightly
improved now. In the current version, a CONSTRUCTION which
takes no parameters can now call another CONSTRUCTION (with
or without parameters).)
- Finally, with REPEAT 150 we indicate that the whole procedure
should be repeated 150 times.
From the main module, we call our animation "Circum" in FAST mode. (This is the default for an ANIMATION.) Run the script and watch them move!
WINDOW 640,400 TWINDOW 2,400, 636,60 IPOINT A = 70,340 IPOINT B = 530,340 IPOINT C = 140,40 TEXT "Look how the circumcircle changes as point A moves towards the line a." CALL Circum FAST TEXT "Press Resume or Exit to end the program.", (255,255,0), (160,0,0) WAIT END CONSTRUCTION Triangle A,B,C c = LINE A,B b = LINE A,C a = LINE B,C MARKPOINT A, -1, 2 MARKPOINT B, -1, 2 MARKPOINT C MARKLINE a MARKLINE b MARKLINE c, -1, 1 REPEAT CONSTRUCTION Circumcircle A,B,C h = MIDLINE B,C, -1, (255,0,0) i = MIDLINE A,C, -1, (255,0,0) j = MIDLINE A,B, -1, (255,0,0) M = CROSS h,i, -1, (128,0,0) MARKPOINT M c1 = CIRCLE M,A, (255,0,0) REPEAT ANIMATION Circum STEP A, 4,-1 TRACE M CALL Triangle FAST A,B,C CALL Circumcircle FAST A,B,C REPEAT 150 |
Here is the output after some repetitions:
Chapter 8: "INTERACTION" procedure
(Introducing INTERACTION, CLICKABLE)
The third procedure type in GeoScript is INTERACTION. It is
similar to ANIMATION in that it redraws the same constructions
from different starting points. But while ANIMATION moves the
points automatically, INTERACTION lets the user drag the points
around, using the mouse.
Let's have a look at this new kind of procedure:
INTERACTION Circum CLICKABLE A, B CALL Triangle FAST A,B,C CALL Circumcircle FAST A,B,C REPEAT
We have no instructions STEP and TRACE here. Instead, we have
the instruction CLICKABLE. It specifies which points can be
dragged with the mouse (in our example A and B). As with TRACE,
after CLICKABLE you can write several points on the same line (up
to 14). Only points can be CLICKABLE, but not lines nor circles.
The clickable points will not be marked in any special way on the
screen. So you must yourself distinguish them by giving them a
special style, or by outputting a text which tells the user which
points he can drag, or both.
An INTERACTION repeats itself infinitely, until the user clicks on the "Exit" button or presses the [Esc] key. Therefore, it is useless to specify a REPEAT number for an INTERACTION.
In FAST mode, an INTERACTION works differently from the other
modes: In FAST mode, while the user is still dragging a point,
the construction will continuously be updated. Actually it looks
as if you were dragging the whole figure around, changing its
form dynamically. This is what you can observe when you run the
following script.
In PACE and SLOW mode however, when you drag a point, the
construction will be updated only after you release the mouse
button.
Now try and run this example script:
WINDOW 640,420 TWINDOW 2,420, 636,40 'We put initialization of points into a CONSTRUCTION, 'so we can call it FAST. CALL Init FAST TEXT "Drag Point A or B with the mouse and see how the circumcircle changes. Click 'Exit' or press [Esc] key to exit." CALL Circum FAST END CONSTRUCTION Init POINT A = 70,340, 4, (255,0,0) POINT B = 530,340, 4, (255,0,0) IPOINT C = 140,40 REPEAT CONSTRUCTION Triangle A,B,C c = LINE A,B b = LINE A,C a = LINE B,C MARKPOINT A, -1, 2 MARKPOINT B, -1, 2 MARKPOINT C MARKLINE a MARKLINE b MARKLINE c, -1, 1 REPEAT CONSTRUCTION Circumcircle A,B,C h = MIDLINE B,C, -1, (0,0,255) i = MIDLINE A,C, -1, (0,0,255) j = MIDLINE A,B, -1, (0,0,255) M = CROSS h,i, -1, (0,0,255) MARKPOINT M c1 = CIRCLE M,A, (0,0,255) REPEAT INTERACTION Circum CLICKABLE A, B CALL Triangle FAST A,B,C CALL Circumcircle FAST A,B,C REPEAT |
Chapter 9: Limiting
movements in animations and interactions
(Introducing ALONG, COPY, FILL)
Sometimes it is useful to move a point (or to let the user drag it), but not anywhere on the screen, but only along a predefined line. For example, in this chapter we want to demonstrate visually the law that all angles drawn over the same chord in a circle are equal. For this purpose we need a circle, a chord, and a point which moves - but only along the circle line. The keyword ALONG allows to domesticate moving points in such a way that they will obey this order. The following example shows the use of ALONG both in an ANIMATION and in an INTERACTION.
In the ANIMATION, we have the following line:
STEP P ALONG c1, 3
This tells the point P that it has to move along the periphery
of the circle c1. (Instead of a circle, you can also specify a
line after ALONG.) - Now, since the point's movement is confined
to a circle, we can no longer give it an x- and a y-coordinate
for its movement. We can give it only a single parameter: the
distance it will move (3 pixels in our example); and the
direction is given by the circle or line it moves ALONG.
For circles, a positive step value means counterclockwise, and a
negative value means clockwise. For lines, a positive value means
forward in the direction of the line's vector, and a negative
value means backward.
Now have a look at the INTERACTION procedure. Here we have a similar line:
CLICKABLE P ALONG c1
With this instruction, the user can drag point P, but it will not be possible to drag it away from the periphery of the circle. If you run the script and try it out, you will see the effect.
Here is the whole program:
WINDOW 640,420 TWINDOW 2,420, 636,40 TEXT "All angles drawn over the same chord in a circle are equal." CONSTRUCT Init FAST ANIMATE MoveAngle FAST TEXT "Now drag yourself the point P around the circle." INTERACT InteractAngle FAST END CONSTRUCTION Init CIRCLE c1, 320,200, 170, (0,0,255) FILL c1, (0,0,255), 20 ILINE invisible, 0,310, 600,310 A,B = CROSS invisible, c1 chord = LINE A,B P = COPY B REPEAT ANIMATION MoveAngle 'Restrict movement of point P to circle c1: STEP P ALONG c1, 3 MARKPOINT P a = LINE P,A, -1, (128,0,0) b = LINE P,B, -1, (128,0,0) MARKNUMBERANGLE a,b, "a" REPEAT 250 INTERACTION InteractAngle 'Restrict movement of point P to circle c1: CLICKABLE P ALONG c1 MARKPOINT P a = LINE P,A, -1, (128,0,0) b = LINE P,B, -1, (128,0,0) MARKNUMBERANGLE a,b, "a" REPEAT |
Two other instructions in this program need explication, both in CONSTRUCTION Init::
FILL c1, (0,0,255), 20
This instruction does not realize any construction. It just
fills the already existing circle c1
with a color. The number 20 indicates the opacity of the fill
color on a scale from 0 to 255. 0 is completely transparent (you
will se nothing of the fill); 255 is full intensity. If the
circle is a partial circle (an arc), only the sector
corresponding to the arc will be filled.
There is another form of the FILL instruction which fills a
triangle; there you must indicate the three points of the
triangle:
FILL point1, point2, point3, color, opacity.
FILL is a relatively slow operation. If you put it into a
procedure which will be called repeatedly in FAST mode, the
screen may flicker if you have an older machine.
The other new instruction in this program is:
P = COPY B
We want the moving point P to start at the same location as
the point B on the circle. So we make a "copy" of B and
put it into the variable P. P will then have exactly the same
coordinates and appearance as B.
You can copy points, lines and circles. However, if you try
"A = COPY a", where A is a
point and a a line, the interpreter
will complaint about a "Type Mismatch" error.
This is the output of the program at two different stages:
Chapter 10: A menu
(Introducing MENU, MENUITEM, EXITMENU, ENDMENU, REPEATMENU)
It is practical to have a menu in a program. (Except that it
makes you think of food when you should be thinking of
programming.) The user can see at a glance what the program
offers, and can choose the options he want.
A GeoScript window does not have a menu, only three predefined
buttons, as you have seen in the previous examples. But you can
program some simple popup menu lists within a GeoScript file.
This is a script for a simple menu:
MENU MENUITEM "Option 1" TEXT "You selected Option 1." MENUITEM "Option 2" TEXT "You selected Option 2." MENUITEM "Option 3" TEXT "You selected Option 3." ENDMENU WAIT END
Of course this menu does not do anything interesting. But it
shows you how it works. You see that it begins with MENU (without
any parameters), followed by a list of MENUITEMs. Following
MENUITEM you have a text string. This is the text which will
appear in the popup list.
Actually, MENU has two optional parameters: You
can give it two color arguments. The first will be the text
color, the second the background color, of the highlighted
menuitem. It is not (yet) possible to change the colors of the
not-highlighted items; these will always appear black on gray.
After a MENUITEM line you put the instructions you want to have
executed for the corresponding item. GeoScript will execute the
instructions it finds after the MENUITEM which was selected by
the user. As soon as it finds a new MENUITEM or an ENDMENU, it
will jump to the line after ENDMENU and continue execution there.
The user can navigate a MENU with the Up and Down arrow keys and
select the highlighted option with [Enter]. Or click an option
with the mouse, of course. - To select nothing, the user can
press the [Esc] key, or click with the mouse outside the menu
list. The program will then continue after ENDMENU without
executing any of the menu options.
But the MENU instruction has more capacities than this. For example, suppose our user has chosen a menu option, the corresponding part of the script has executed, and then the user would like to choose another option of the same menu. But the menu list is already gone. How do we get back to it? - You can do this by ending your menu list with REPEATMENU instead of ENDMENU. This makes the menu appear repeatedly, every time execution of a menu option has ended. But then of course we have another problem: how does the user ever get out of this menu? It will repeat itself infinitely. That is, it would - if there were not the instruction EXITMENU. Put EXITMENU at the end of the instructions of a menu item, and program execution will jump after REPEATMENU. So we will slightly change our first menu list:
MENU MENUITEM "Option 1" TEXT "You selected Option 1." MENUITEM "Option 2" TEXT "You selected Option 2." MENUITEM "Option 3" TEXT "You selected Option 3." MENUITEM "Get out of this boring menu" TEXT "You decided to exit the menu." EXITMENU REPEATMENU WAIT END
This menu will repeat itself until the user selects the fourth option (or until he presses [Esc] or clicks outside the menu list).
But there is even more. You can also nest menus: a MENUITEM can in turn contain a new MENU list. You will see this in the following example script. It contains the same animation and interaction as the script from Chapter 9, but now the user can choose between animation and interaction, and he can choose the execution mode.
WINDOW 640,420 TWINDOW 2,420, 636,40 CALL Init FAST MENU MENUITEM "Animate construction automatically" TEXT "All angles drawn over the same chord in a circle are equal." MENU MENUITEM "FAST mode (animating)" ANIMATE MoveAngle FAST MENUITEM "PACE mode (show construction steps)" ANIMATE MoveAngle PACE MENUITEM "SLOW mode (show drawing tools)" ANIMATE MoveAngle SLOW ENDMENU MENUITEM "Show construction interactively" TEXT "Now drag yourself the point P around the circle." MENU MENUITEM "FAST mode (animating)" INTERACT InteractAngle FAST MENUITEM "PACE mode (show construction steps)" INTERACT InteractAngle PACE MENUITEM "SLOW mode (show drawing tools)" INTERACT InteractAngle SLOW ENDMENU MENUITEM "Exit program" EXITMENU REPEATMENU END CONSTRUCTION Init CIRCLE c1, 320,200, 170, (0,0,255) FILL c1, (0,0,255), 20 ILINE invisible, 0,310, 600,310 A,B = CROSS invisible, c1 chord = LINE A,B P = COPY B REPEAT ANIMATION MoveAngle 'Restrict movement of point P to circle c1: STEP P ALONG c1, 3 MARKPOINT P a = LINE P,A, -1, (128,0,0) b = LINE P,B, -1, (128,0,0) MARKNUMBERANGLE a,b, "a" REPEAT 250 INTERACTION InteractAngle 'Restrict movement of point P to circle c1: CLICKABLE P ALONG c1 MARKPOINT P a = LINE P,A, -1, (128,0,0) b = LINE P,B, -1, (128,0,0) MARKNUMBERANGLE a,b, "a" REPEAT |
This is how the main menu list appears on the screen: |
Chapter 11: Changing
default styles and colors
(Introducing DEFAULTS, TOOLDEFAULTS)
GeoScript has certain default values for colors, point and
line properties, etc, which it applies to every element whose
properties are not indicated explicitly in the script. If you
want an element to appear differently, you have to explicitly
indicate its color, style, and thickness.
However, there is also a way to change the default appearance of
elements for the whole program at once. This is done with the
instruction DEFAULTS, which has the following syntax:
DEFAULTS bgColor [, drawColor, textColor, auxColor, lineThickness, pattern, pointThickness, style, anglePosition, arcWidth]
The parameters have the following meaning:
bgColor = background color of the application window.
drawColor = color with which the geometrical elements
are drawn by default.
textColor = default color of text.
auxColor = color of the auxiliary lines which appear in
detailed predefined constructions in PACE and SLOW mode.
lineThickness = default thickness of lines and circles.
pattern = default pattern of lines.
pointThickness = default thickness of points.
style = default style of points.
anglePosition = default value of the optional
"position" parameter in MARKANGLE.
arcWidth = default width (in degrees) of the auxiliary
arcs which appear in detailed predefined constructions in PACE
and SLOW mode.
The instruction DEFAULTS will change these values as you indicate them, for all following drawing instructions. Remember that it does NOT change the appearance of the window and objects already drawn. Therefore, using DEFAULTS makes sense only when you are initializing a new construction.
There is also an instruction TOOLDEFAULTS which changes the appearance of the tools drawn in SLOW / TOOLS mode. Its syntax is:
TOOLDEFAULTS pencilSize [, squareSize, rulerWidth, pencilColor, compassColor, squareColor, protractorColor, rulerColor]
The parameters should be self-explaining. pencilSize
applies not only to the pencil, but also to the compass. squareSize
applies not only to the square, but also to the protractor.
(Square and protractor appear only with the LINEPOLAR
instruction.)
A value of -1 in the color parameters of TOOLDEFAULTS has a
special meaning: it makes the corresponding tool appear in the
same color as the element it is drawing. GeoScript sets this
value initially for the pencil: you may have noted in the
previous examples that the pencil is always drawn in the color of
the line or point it draws.
The following example shows the effect of changes applied with DEFAULTS and TOOLDEFAULTS. Additionally, we change the highlight colors of the menu.
DEFAULTS 0, (255,180,255), (255,255,0), (0,0,128), 3, &HF01, 20, 2, 0, 45º TOOLDEFAULTS 50, 100, 20, (0,255,0), (0,160,0), (160,160,0), (160,0,0), (50,90,50) CLS 0 'DEFAULTS does NOT change the background which is already drawn! 'except if you have a SCREEN instruction after DEFAULTS. WINDOW 640,420 TWINDOW 2,420, 636,40 CALL Init FAST MENU (255,255,0), (190,0,0) MENUITEM "Animate construction automatically" TEXT "All angles drawn over the same chord in a circle are equal." MENU MENUITEM "FAST mode (animating)" ANIMATE MoveAngle FAST MENUITEM "PACE mode (show construction steps)" ANIMATE MoveAngle PACE MENUITEM "SLOW mode (show drawing tools)" ANIMATE MoveAngle SLOW ENDMENU MENUITEM "Show construction interactively" TEXT "Now drag yourself the point P around the circle." MENU MENUITEM "FAST mode (animating)" INTERACT InteractAngle FAST MENUITEM "PACE mode (show construction steps)" INTERACT InteractAngle PACE MENUITEM "SLOW mode (show drawing tools)" INTERACT InteractAngle SLOW ENDMENU MENUITEM "Exit program" EXITMENU REPEATMENU END CONSTRUCTION Init CIRCLE c1, 320,200, 170, (0,0,255) FILL c1, (0,0,255), 20 ILINE invisible, 0,310, 600,310 A,B = CROSS invisible, c1 chord = LINE A,B P = COPY B REPEAT ANIMATION MoveAngle 'Restrict movement of point P to circle c1: STEP P ALONG c1, 3 MARKPOINT P a = LINE P,A, -1, (128,0,0) b = LINE P,B, -1, (128,0,0) c = BISECTOR a,b MARKNUMBERANGLE a,b, "a" REPEAT 250 INTERACTION InteractAngle 'Restrict movement of point P to circle c1: CLICKABLE P ALONG c1 MARKPOINT P a = LINE P,A, -1, (128,0,0) b = LINE P,B, -1, (128,0,0) c = BISECTOR a,b MARKNUMBERANGLE a,b, "a" REPEAT |
Here is an example of the output:
Now that you have mastered the basics of GeoScript, nothing will stop you from writing the most fabulous scripts!
If you write an interesting script and want to share it with other GeoScript users, send it to: