Universität Ulm, Fakultät für Mathematik und Wirtschaftswissenschaften, SAI

# Lösung zu Blatt 1 --- Allgemeine Informatik II (WS 1999)

## 1. Verschachtelt

```MODULE Plottest;

IMPORT Arguments;
IMPORT MathLib;
IMPORT Plot;
IMPORT StdIO;

CONST
maxx = 4000.0;
maxy = 4200.0;

TYPE Point = RECORD x, y: REAL; END;

PROCEDURE Line(x, y: Point); (* Points between (0,0) and (1,1) *)
BEGIN
Plot.Line(TRUNC(maxx * x.x), TRUNC(maxy * x.y),
TRUNC(maxx * y.x), TRUNC(maxy * y.y));
END Line;

PROCEDURE Middle(x, y: Point; VAR res: Point);
BEGIN
res.x := 0.5 * (x.x + y.x);
res.y := 0.5 * (x.y + y.y);
END Middle;

PROCEDURE Generate(x, y, z: Point; n: INTEGER);
VAR xy, xz, yz, np2: Point;
BEGIN
Line(x, y); Line(x, z); Line(y, z);
IF n > 0 THEN
Middle(x, y, xy); Middle(x, z, xz); Middle(y, z, yz);
Generate(x, xy, xz, n - 1);
Generate(y, xy, yz, n - 1);
Generate(z, xz, yz, n - 1);
END;
END Generate;

VAR x, y, z: Point;
gen: INTEGER;

BEGIN
Arguments.InitArgs("#Generations");
Arguments.FetchInt(gen);
Arguments.AllArgs;
x.x := 0.0; x.y := 0.0;
y.x := 1.0; y.y := 0.0;
z.x := 0.5; z.y := MathLib.sqrt(0.75);
Plot.OpenPlot(StdIO.stdout);
Generate(x, y, z, gen);
Plot.ClosePlot();
END Plottest.
```

Ingo Melzer, 20. April 1999