forked from ThomasMertes/seed7
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhilbert.sd7
107 lines (97 loc) · 3.56 KB
/
hilbert.sd7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
(********************************************************************)
(* *)
(* hilbert.sd7 Display a Hilbert curve. *)
(* Copyright (C) 2011 Thomas Mertes *)
(* *)
(* This program is free software; you can redistribute it and/or *)
(* modify it under the terms of the GNU General Public License as *)
(* published by the Free Software Foundation; either version 2 of *)
(* the License, or (at your option) any later version. *)
(* *)
(* This program is distributed in the hope that it will be useful, *)
(* but WITHOUT ANY WARRANTY; without even the implied warranty of *)
(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *)
(* GNU General Public License for more details. *)
(* *)
(* You should have received a copy of the GNU General Public *)
(* License along with this program; if not, write to the *)
(* Free Software Foundation, Inc., 51 Franklin Street, *)
(* Fifth Floor, Boston, MA 02110-1301, USA. *)
(* *)
(********************************************************************)
$ include "seed7_05.s7i";
include "draw.s7i";
include "keybd.s7i";
const integer: delta is 8;
const proc: drawDown (inout integer: x, inout integer: y, in integer: n) is forward;
const proc: drawUp (inout integer: x, inout integer: y, in integer: n) is forward;
const proc: drawRight (inout integer: x, inout integer: y, in integer: n) is func
begin
if n > 0 then
drawDown(x, y, pred(n));
line(x, y, 0, delta, white);
y +:= delta;
drawRight(x, y, pred(n));
line(x, y, delta, 0, white);
x +:= delta;
drawRight(x, y, pred(n));
line(x, y, 0, -delta, white);
y -:= delta;
drawUp(x, y, pred(n));
end if;
end func;
const proc: drawLeft (inout integer: x, inout integer: y, in integer: n) is func
begin
if n > 0 then
drawUp(x, y, pred(n));
line(x, y, 0, -delta, white);
y -:= delta;
drawLeft(x, y, pred(n));
line(x, y, -delta, 0, white);
x -:= delta;
drawLeft(x, y, pred(n));
line(x, y, 0, delta, white);
y +:= delta;
drawDown(x, y, pred(n));
end if;
end func;
const proc: drawDown (inout integer: x, inout integer: y, in integer: n) is func
begin
if n > 0 then
drawRight(x, y, pred(n));
line(x, y, delta, 0, white);
x +:= delta;
drawDown(x, y, pred(n));
line(x, y, 0, delta, white);
y +:= delta;
drawDown(x, y, pred(n));
line(x, y, -delta, 0, white);
x -:= delta;
drawLeft(x, y, pred(n));
end if;
end func;
const proc: drawUp (inout integer: x, inout integer: y, in integer: n) is func
begin
if n > 0 then
drawLeft(x, y, pred(n));
line(x, y, -delta, 0, white);
x -:= delta;
drawUp(x, y, pred(n));
line(x, y, 0, -delta, white);
y -:= delta;
drawUp(x, y, pred(n));
line(x, y, delta, 0, white);
x +:= delta;
drawRight(x, y, pred(n));
end if;
end func;
const proc: main is func
local
var integer: x is 11;
var integer: y is 11;
begin
screen(526, 526);
KEYBOARD := GRAPH_KEYBOARD;
drawRight(x, y, 6);
readln(KEYBOARD);
end func;