
(********************************************************************)
(*                                                                  *)
(*  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;
