home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
magazine
/
drdobbs
/
1988
/
04
/
porter
/
porter.ls3
< prev
next >
Wrap
Text File
|
1979-12-31
|
2KB
|
85 lines
STRUCTURED PROGRAMMINMG LISTING THREE APRIL ISSUE
MODULE Sierpin;
(* Based on the Sierpinski recursive model in N. Wirth's book *)
(* "Programming in Modula-2." *)
(* Wirth's program has been modified slightly to accommodate *)
(* EGA graphics mode on the IBM PC. *)
(* Written by K. Porter for DDJ, April 1988 issue. *)
(* ---------------------------------------------------------- *)
FROM InOut IMPORT Read;
FROM LineDwg IMPORT width, height, Px, Py, clear, line;
FROM SYSTEM IMPORT REGISTERS, INT;
CONST SquareSize = 512;
VAR i, h, x0, y0 : CARDINAL;
ch : CHAR;
reg : REGISTERS;
PROCEDURE A (k : CARDINAL);
BEGIN
IF k > 0 THEN
A (k-1); line (7, h); B (k-1); line (0, 2*h);
D (k-1); line (1, h); A (k-1)
END
END A;
(* -------------------------- *)
PROCEDURE B (k : CARDINAL);
BEGIN
IF k > 0 THEN
B (k-1); line (5, h); C (k-1); line (6, 2*h);
A (k-1); line (7, h); B (k-1)
END
END B;
(* -------------------------- *)
PROCEDURE C (k : CARDINAL);
BEGIN
IF k > 0 THEN
C (k-1); line (3, h); D (k-1); line (4, 2*h);
B (k-1); line (5, h); C (k-1)
END
END C;
(* -------------------------- *)
PROCEDURE D (k : CARDINAL);
BEGIN
IF k > 0 THEN
D (k-1); line (1, h); A (k-1); line (2, 2*h);
C (k-1); line (3, h); D (k-1)
END
END D;
(* -------------------------- *)
BEGIN
clear;
i := 0;
h := SquareSize DIV 4;
x0 := CARDINAL (width) DIV 2;
y0 := CARDINAL (height) DIV 2 + h;
REPEAT
i := i + 1;
x0 := x0 - h;
h := h DIV 2;
y0 := y0 + h;
Px := x0;
Py := y0;
A (i); line (7, h); B (i); line (5, h);
C (i); line (3, h); D (i); line (1, h);
UNTIL (i = 4);
Read (ch); (* hold for keypress *)
reg.AH := 0;
reg.AL := 3; (* restore 80 x 25 color text mode *)
INT (16, reg);
END Sierpin.