A graphical pascal extension based on graphical types

August 21, 2017 | Autor: N. Magnenat-halmann | Categoría: Computer Graphics, Pascal
Share Embed


Descripción

SOFTWARE-PRACTICE

A N D EXPERIENCE, VOL. 1 1 , 53-62 (1981)

A Graphical Pascal Extension Based on Graphical Types" NADIA MAGNENAT-THALMANN

De'partement des Me'thodes Quantitatives, Ecole des Hautes, Etudes Commerciales, Montre'al, Canada AND DANIEL T H A L M A N N

De'partement d'lnformatique et de Recherche Ope'rationnelle, Universite' de Montre'al, Montre'al, P. Que'bec, Canada, H 3 C 3J7

SUMMARY The goal of this paper is to present a graphical Pascal extension, named MIRA. This extension gives the user the means of defining and using specific graphical types. A complete vector arithmetic has been developed and a new structured type has been introduced the figure type. Instructions to create and delete figures are discussed and it is shown how the graphical types can be used as other Pascal types. The implementation is carried out by a portable Pascal preprocessor. KEY WORDS

Computer graphics

Pascal

Graphical types

INTRODUCTION Graphical processing requires that a language have well-developed arithmetic and graphical capabilities, both to be used simultaneously. The use of graphical software packages such as CALCOMP,' GINO-F,2 GPGS3 or TEKTRONIX4 has been very popular for a long time. A shortcoming of these packages, however, is that the only simple graphical variable is the co-ordinate and the only structured graphical variable is the array of co-ordinates. There are no graphical instructions, there are only subroutine calls; consequently, there is no distinction between graphical processing and any other processing; this results in a lack of explicitness. High-level graphical languages, such as IMAGE,5have already been designed, but they are very much problem-oriented. This means that they generally do not offer good arithmetic functions and their 'nongraphical' features are not rich enough. Our task has been to develop a graphical extension of a well-known language, as has been done for SNOBOL,6 FORTRAN,7 ALGOL 60,8 PL/1,9 EULER" and ALGOL 68." In their extension, only graphical variables and not graphical types are present. T h e purpose of this paper is to present a graphical Pascal' extension, named MIRA. What is new in our approach? i. Since Pascal has become very popular in the university world, a Pascal extension, as such, can prove to be very u ~ e f u 1 . lPascal ~ is the subject of many research * This research was supported by the

National Research Council of Canada, Grants A3066 and E4262.

0038-0644/81/010053-1 O$Ol .OO @ 1981 by John Wiley & Sons, Ltd.

Received 1 7 January 1979

54

N . MAGNENAT-THALMANN A N D D. T H A L M A N N

papers14 and many universities have chosen Pascal as a teaching tool in introductory, intermediate and advanced computer science courses. We have discussed this choice in a previous paper.' A graphical Pascal extension does not then constitute a break in computer science methodology. ii. Good graphics programming requires the creation of basic graphical types and a method to construct more complicated graphical types. This point is fundamental. A variable of square type must be easily distinct from a variable of circle type. When we write a function to calculate the cubic root of a real number, we find that it is necessary to check if the actual parameter is not a character. T h e same problem must be solved in graphical processing; writing a procedure to find the intersection point of the diagonals of a quadrilateral has no significance if the actual parameter is a circle. It is necessary to give the user the means of defining and using specific graphical types. T h e best language for this purpose is most certainly Pascal, because it is a general-purpose language which allows the programmer to build new types. iii. T h e extension has been implemented by a portable preprocessor written in standard Pascal.12 T h e output is a standard Pascal program which requires a small run-time library written in Pascal with only one hardware-oriented procedure. T h e graphical devices used are a display HP2648A and a VERSATEC printer. We will present the main features of MIRA in the following sections.

T H E VECTOR TYPE T h e vector type has been introduced and can be used in the same way as the real type. A vector can be given by its two co-ordinates $ E l , E2 %, where El and E2 are real expressions. An example is shown in Figure 1 . A vector arithmetic has been developed using vector addition and a scalar product. A vector can be read and written.

PROGRAM ONE(INPUT, OUTPUT); VAR A, B, C : VECTOR; R: REAL; BEGIN B : = $3.4, 4.2%; READLN(C); A : = B+C; R : =B*C; WRlTELN(A,R) END. A vector can be the result of a function. For example, the function that rotates a vector around the origin is the following:

FUNCTION ROT(V: VECTOR; ALPHA: REAL): VECTOR; VAR C, S : REAL; BEGIN C : = COS(ALPHA); S : = SIN(ALPHA); ROT : = $ V * $C, - S % , V*$S, C B 9 END;

A GRAPHICAL PASCAL EXTENSION

55

3.4

Figure 1. A vector

T H E F I G U R E TYPE In MIRA, a new structured type has been introduced, the figure type. It is the essential feature of our extension. Its great capacities are due to the possibilities of using the figure type in the same way as other types. A figure type is defined as: t y p e e g u r e type identi$er) = figure((formal parameter section) {;(formal parameter section))); (declaration p a r t ) begin(statement) {;(statement))

end; T h e syntax of a figure type is similar to the syntax of the Brinch Hansen monitor typeI6 because there are parameters, local declarations and instructions in the definition. Parameters are the characteristics of the figure, for example, a circle is determined by its radius and its centre, a segment by its two vectors, a triangle by three. T h e following instructions allow us to build a figure. For example, we define a quadrilateral as:

TYPE QUADRILATERAL = FIGURE (Xl, X2, X3, X4: VECTOR); BEGIN CONNECT ( X l , X2, X3, X4, X1) END; T h e connect statement is specific to a figure type; it connects the different vectors. T h e quadrilateral type is perhaps less interesting because of its simplicity; a more interesting example is the ellipse type:

TYPE ELLIPSE = FIGURE(CENTRE: VECTOR; A, B: REAL); VAR THETA, STEP: REAL; X1, X2: VECTOR; BEGIN THETA : = 0.0; X1 : =
Lihat lebih banyak...

Comentarios

Copyright © 2017 DATOSPDF Inc.