RECORD.
VAR
c1, c2, c3:
RECORD
(* variable-declarations *)
re, img: REAL;
END;
BEGIN
WrLn;
c1.re := 3.5;
c1.img := -4.76;
c2.re := 4.0;
c2.img := 14.6;
(* sum *)
c3.re := c1.re + c2.re;
c3.img := c1.img + c2.img;
(* print *)
WrStr("The complex sum of ");WrFixReal(c1.re, 1,
0);WrChar('+');
WrFixReal(c1.img, 1, 0);WrChar('i');
WrStr(" and ");WrFixReal(c2.re, 1,
0);WrChar('+'); WrFixReal(c2.img, 1, 0);WrChar('i');
WrStr(" is: ");WrFixReal(c3.re, 2,
0);WrChar('+'); WrFixReal(c3.img, 2, 0);WrChar('i');WrLn;
END D1.
MODULE S5;
<* WOFF + *> <* NOOPTIMIZE + *>
FROM IO IMPORT WrStr, WrLn, RdCard, WrCard, RdInt, WrInt, RdKey,
RdLn, WrFixReal;
FROM Windows IMPORT VK_ESCAPE;
FROM Wimdows IMPORT SetFont, Text, GetKeyPressed;
FROM Wimdows IMPORT Window, KillWindow, Line, Ellipse, Disc, Circle,
Rectangle, _clrBLACK, _clrBLUE, _clrGREEN, _clrCYAN, _clrRED,
_clrMAGENTA;
FROM RealMath IMPORT cos, sin, pi;
FROM Lib IMPORT Delay; (* Wait n milliseconds *)
CONST SCREEN_SIZE = 600;
TYPE LedemaatRc = RECORD
x,y: CARDINAL;
lengte, lengteVoet: CARDINAL;
hoek: INTEGER; (* in graden *)
kleur: CARDINAL;
END;
PROCEDURE TekenLedemaat(ledemaat: LedemaatRc);
VAR hoek_rad, x2, y2, x3, y3: REAL;
BEGIN
hoek_rad := VAL(REAL, ledemaat.hoek) * pi / 180.0;
x2 := VAL(REAL, ledemaat.x) + VAL(REAL, ledemaat.lengte) *
sin(hoek_rad);
y2 := VAL(REAL, ledemaat.y) + VAL(REAL, ledemaat.lengte) *
cos(hoek_rad);
Line(ledemaat.x, ledemaat.y, VAL(CARDINAL, x2), VAL(CARDINAL,
y2), ledemaat.kleur);
IF ledemaat.lengteVoet > 0 THEN
x3 := x2 + VAL(REAL, ledemaat.lengteVoet) *
cos(hoek_rad);
y3 := y2 - VAL(REAL, ledemaat.lengteVoet) *
sin(hoek_rad);
Line(VAL(CARDINAL, x2), VAL(CARDINAL, y2),
VAL(CARDINAL, x3), VAL(CARDINAL, y3), ledemaat.kleur);
END;
END TekenLedemaat;
(*********************************************************************************)
VAR k: CARDINAL;
ledemaat: LedemaatRc;
BEGIN
WrLn;
Window("Exercise S5",SCREEN_SIZE,SCREEN_SIZE);
ledemaat.x := 100;
ledemaat.y := 100;
ledemaat.lengte := 100;
ledemaat.lengteVoet := 20;
ledemaat.hoek := -60;
ledemaat.kleur := _clrRED;
TekenLedemaat(ledemaat);
(* tell user to press escape to finish the program... *)
SetFont(1, _clrRED);
Text("press ESC to quit", SCREEN_SIZE/2-50, 10);
(* ...and program will wait here until user presses escape *)
REPEAT
Delay(25);
UNTIL (GetKeyPressed(k) AND (k = VK_ESCAPE));
(* finally close the window *)
KillWindow();
END S5.
BEGIN
Line(x0, y0, x1, y1, colour);
IF x1 # x0 THEN
alfa :=
arctan((FLOAT(y1)-FLOAT(y0))/(FLOAT(x1)-FLOAT(x0)));
ELSE
IF y1 > y0 THEN
alfa := PI/2.0;
ELSE
alfa := -PI/2.0;
END;
END;
xa[1] := x1;
ya[1] := y1;
xa[2] := VAL(INTEGER, x1) - VAL(INTEGER, FLOAT(size) *
cos(alfa
+ ANGLE));
ya[2] := VAL(INTEGER, y1) - VAL(INTEGER, FLOAT(size) *
sin(alfa
+ ANGLE));
xa[3] := VAL(INTEGER, x1) - VAL(INTEGER, FLOAT(size) *
cos(alfa
- ANGLE));
ya[3] := VAL(INTEGER, y1) - VAL(INTEGER, FLOAT(size) *
sin(alfa
- ANGLE));
Polygon(3, xa, ya, colour, TRUE);
END Arrow;