Previous page
Next page

WGL recognizes seven different types of objects.  These data types are: distance, point, line, circle, polygon, counter, and color.  Some of these data types, such as color and counter, can only be used in very limited ways, while others, such as distance, can be more extensively manipulated.

Every object, regardless of its type, must take the form of either a constant or a variable.  A constant is a value of a particular type that does not change over time.  An example of a distance constant is 3.  An example of a constant of type color is blue.  We say that these are constants since their “meaning” or “value” never changes:  3 is always 3 and blue is always blue.  Values for any of the seven WGL data types can be represented using appropriate constants.  As we shall see below, fixed rules exist that specify the precise form of each type of constant.

A color constant is simply the name of a common color.  Examples are green, red, blue, and white.  Bad and good, as you would expect, are not valid colors.  What about something like teal?  The answer is no, since teal is not considered “common” enough to be included in WGL.  In general, you will not have to worry about borderline cases like these; since the way colors are specified in WGL is to select them from a palette of available colors.  If the color is listed, then it is available.  If it is not listed, it is not available.

Distance and counter constants take the form of non-negative integers.  An integer is a whole number without a fraction.  Non-negative integers are just numbers, like 5, 15, and 99.  Each of these would be a valid distance or counter constant.  Distance and counter constants are composed of the digits 0 through 9.  They may not contain commas, decimal points, or any other special characters.  Hence, 12.50 and 1,250 are not valid distances or counters.  Constants of these types must also be non-negative, so -25 would not be valid either.  Both counters and distances have a limited range of acceptable values.  Distances can vary from 0 to 999, inclusive; while counters are limited to the range 1 - 99, inclusive. A counter value of zero is not allowed.

In addition to constants, most programming languages allow the programmer to define variables.  A variable is a named object that can store a value of a particular type.  Unlike constants whose values are always fixed, the value of a variable can change.  At any particular point in time a variable will hold some specific value, but the programmer has the ability to change the value stored in that variable.  Every variable has an associated type that describes the kinds of values that it can hold.  WGL allows the programmer to define variables of type: distance, point, line, polygon, and circle.  Variables of type color and counter are not allowed.  These objects can exist only as constants in WGL.

A variable of type distance can hold a single integer value in the range 0 to 999, inclusive.  Distance variables are always named beginning with the letter “d” followed by one or more digits (e.g., d1 or d5). So, if d1 were declared to be a variable of type distance, it could hold a value such as 100.  As you might expect, a distance variable is usually used to indicate how far away something is.

An object of type point specifies a location using two distances: a horizontal, X, distance and a vertical, Y, distance.  These distances are measured from the opposite axis: the X distance from the Y axis and the Y distance from the X axis.  Constants of type point are expressed as these two distances, first X, then Y, separated by a comma and enclosed in parentheses.  In other words, point constants take the form of (X, Y) where X and Y are distance constants.  For example, (100,150) and (50,50) are point constants.

In addition to constants, the location of a point may also be specified by an expression.  An expression in WGL is a collection of constants and/or variables, together with appropriate parentheses, that evaluate to a value of a particular type, such as point, line, circle, or polygon.  Hence, if d1held a value of 100 and d2 a value of 200 then the expressions (d1, d2), (100, d2), and (d1, 200) each would specify a point at (100,200).  

Variables of type point are always named beginning with the letter “p” followed by one or more digits (e.g., p1 or p3).  If p1 were declared to be a point variable, it could hold any valid point value.  Note, however, that it could not hold a distance such as 25, since 25 is not a valid point.

An object of type line specifies a straight line segment between two points.  Line constants are composed of two points, separated by a comma and enclosed in parentheses.  In other words, they take the form of ( START, END ) where  START  and  END  are points.  For example, ( (100, 100), (200, 200) ) is a valid line constant that specifies a line segment starting at (100, 100) and ending at (200, 200).  The first point is always the starting point and the second point is always the ending point of the line segment.  Lines may be expressed using either constants or expressions, such as: (p1, p2)  where p1 and p2 are points, or ( (d1, d2), (d3, d4) )  where d1, d2, d3, and d4 are all of type distance.  Variables of type line are always named beginning with the letter “l” followed by one or more digits (e.g., l1 or l5).  Remember that a variable of type line can hold any valid line but cannot hold anything else, such as an individual point or distance.

An object of type circle specifies a circle using a center point and radius.  A value of type circle is composed of a point and a distance, separated by a comma and enclosed in parentheses.  It takes the form of (CENTER, RADIUS) where CENTER is the center point of the circle and RADIUS is the circle’s radius.  For example, if c1 were a variable of type circle, it could be defined by an expression such as (p1, d1) where p1 is a point and d1 is a distance, or ( (d1, d2), d3) where d1, d2, and d3 are all distance variables, or even the circle constant ( (100, 100), 50).  Variables of type circle are always named beginning with the letter “c” followed by one or more digits.

The final object type recognized by WGL is the polygon.  As was described in Section 6.3, a polygon is a closed, multi-sided figure.  Polygons are expressed in WGL as a list of points separated by commas and enclosed in parentheses.  WGL connects these points together with line segments to form a closed figure.  A line will be drawn from the first point in the list to the second point, another line from the second point to the third, and so on.  In order to ensure that the figure is closed, the last point in the polygon list must be identical to the first point in the list.

For example, if g1 were a polygon, a triangle in this case, it could be expressed as the following list of points: ( p1, p2, p3, p1).  In this example, lines would be implicitly defined from p1 to p2; from p2 to p3; and from p3 back to p1.  We can also express this polygon using only distance variables, such as:  ( ( d1, d2), (d3, d4), (d5, d6), (d1, d2) ) or even distance constants, such as:  ( (100, 100), (200, 100), (150, 150), (100, 100) ).  Variables of type polygon are always named beginning with the letter “g”, since we are already using “p” for points, followed by one or more digits.  Hence, g1, g3, and g5 are all valid polygon names.


Return to top