kolibrios-fun/programs/develop/oberon07/Samples/Windows/Console/SierpinskiCarpet.ob07
maxcodehack 2f54c7de00 Update oberon07 from akron1's github
git-svn-id: svn://kolibrios.org@8097 a494cfbc-eb01-0410-851d-a64ba20cac60
2020-10-13 07:58:51 +00:00

75 lines
1.2 KiB
Plaintext

(*
adapted to Oberon-07 by 0CodErr, KolibriOS team
*)
MODULE SierpinskiCarpet;
IMPORT In, Out, Console;
VAR
order: INTEGER;
PROCEDURE pow(b, n: INTEGER): INTEGER;
VAR
i, res: INTEGER;
BEGIN
res := 1;
FOR i := 1 TO n DO
res := res * b
END
RETURN res
END pow;
PROCEDURE in_carpet(x, y: INTEGER): BOOLEAN;
VAR
res, exit: BOOLEAN;
BEGIN
exit := FALSE;
res := TRUE;
WHILE (x > 0) & (y > 0) & (exit = FALSE) DO
IF (x MOD 3 = 1) & (y MOD 3 = 1) THEN
res := FALSE;
exit := TRUE
END;
y := y DIV 3;
x := x DIV 3
END
RETURN res
END in_carpet;
PROCEDURE PrintSierpinski(n: INTEGER);
VAR
i, j, l: INTEGER;
BEGIN
l := pow(3, n) - 1;
FOR i := 0 TO l DO
FOR j := 0 TO l DO
IF in_carpet(i, j) THEN
Out.Char("#")
ELSE
Out.Char(" ")
END
END;
Out.Ln
END
END PrintSierpinski;
BEGIN
Console.open;
Out.String("Input carpet order(0..3):");
In.Int(order);
PrintSierpinski(order);
In.Ln;
Console.exit(TRUE)
END SierpinskiCarpet.