forked from ThomasMertes/seed7
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdragon.sd7
72 lines (64 loc) · 2.53 KB
/
dragon.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
(********************************************************************)
(* *)
(* dragon.sd7 Draw a dragon curve *)
(* Copyright (C) 2010 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 "float.s7i";
include "math.s7i";
include "draw.s7i";
include "keybd.s7i";
var float: angle is 0.0;
var integer: x is 220;
var integer: y is 220;
const proc: turn (in integer: degrees) is func
begin
angle +:= flt(degrees) * PI / 180.0
end func;
const proc: forward (in float: length) is func
local
var integer: x2 is 0;
var integer: y2 is 0;
begin
x2 := x + trunc(cos(angle) * length);
y2 := y + trunc(sin(angle) * length);
lineTo(x, y, x2, y2, black);
x := x2;
y := y2;
end func;
const proc: dragon (in float: length, in integer: split, in integer: direct) is func
begin
if split = 0 then
forward(length);
else
turn(direct * 45);
dragon(length/1.4142136, pred(split), 1);
turn(-direct * 90);
dragon(length/1.4142136, pred(split), -1);
turn(direct * 45);
end if;
end func;
const proc: main is func
begin
screen(976, 654);
clear(curr_win, white);
KEYBOARD := GRAPH_KEYBOARD;
dragon(768.0, 14, 1);
ignore(getc(KEYBOARD));
end func;