
(********************************************************************)
(*                                                                  *)
(*  bifurk.sd7    Display the bifurcation diagram                   *)
(*  Copyright (C) 2006  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 "draw.s7i";
  include "keybd.s7i";

const integer: DRAW_START is 100;
const integer: DRAW_END is 200;
const float: G_MIN is 0.0;
const float: G_MAX is 4.0;
const float: KRES is (G_MAX - G_MIN) / 1000.0;
const float: XSTART is 0.5;


const proc: bifurk is func
  local
    var float: k is 0.0;
    var float: x is 0.0;
    var integer: i is 0;
    var integer: xPos is 0;
  begin
    k := G_MIN;
    while k < G_MAX do
      x := XSTART;

      for i range 0 to pred(DRAW_START) do
        x := k * x * (1.0 - x);
      end for;

      xPos := round(k * 250.0);
      for i range DRAW_START to DRAW_END do
        x := k * x * (1.0 - x);
        point(xPos, round(x * 700.0), black);
      end for;

      k +:= KRES;
    end while;
  end func;


const proc: main is func
  begin
    screen(1024, 768);
    clear(curr_win, white);
    KEYBOARD := GRAPH_KEYBOARD;
    bifurk;
    DRAW_FLUSH;
    ignore(getc(KEYBOARD));
  end func;
