
(********************************************************************)
(*                                                                  *)
(*  clock3.sd7    Analog Clock                                      *)
(*  Copyright (C) 2007 Volker Schuller                              *)
(*                                                                  *)
(*  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";
  include "time.s7i";
  include "duration.s7i";

const integer: WINDOW_WIDTH is 200;
const integer: WINDOW_HEIGHT is 200;
const color: BACKGROUND is White;
const color: FOREGROUND is Black;
const color: CLOCKCOLOR is Aqua;

const proc: main is func
  local
    var char: command is ' ';
    var time: start_time is time.value;
    var float: alpha is 0.0;
    var integer: x is 0;
  begin
    screen(WINDOW_WIDTH, WINDOW_HEIGHT);
    clear(curr_win, BACKGROUND);
    KEYBOARD := GRAPH_KEYBOARD;
    command := busy_getc(KEYBOARD);
    while command <> 'q' do
      start_time := truncToSecond(time(NOW));
      clear(curr_win, BACKGROUND);
      fcircle(100, 100, 95, CLOCKCOLOR);
      circle(100, 100, 95, FOREGROUND);
      for x range 0 to 60 do
        alpha := flt(x-15) * PI / 30.0;
        if x mod 5 = 0 then
          lineTo(100 + round(cos(alpha)*95.0),
                 100 + round(sin(alpha)*95.0),
                 100 + round(cos(alpha)*85.0),
                 100 + round(sin(alpha)*85.0), FOREGROUND);
        else
          lineTo(100 + round(cos(alpha)*95.0),
                 100 + round(sin(alpha)*95.0),
                 100 + round(cos(alpha)*92.0),
                 100 + round(sin(alpha)*92.0), FOREGROUND);
        end if;
      end for;
      alpha := flt(start_time.second-15) * PI / 30.0;
      lineTo(100, 100, 100 + round(cos(alpha)*85.0), 100 + round(sin(alpha)*85.0), FOREGROUND);
      alpha := flt(start_time.minute-15) * PI / 30.0;
      lineTo(100 + round(cos(alpha-PI/2.0)*5.0),
             100 + round(sin(alpha-PI/2.0)*5.0),
             100 + round(cos(alpha)*75.0),
             100 + round(sin(alpha)*75.0), FOREGROUND);
      lineTo(100 + round(cos(alpha+PI/2.0)*5.0),
             100 + round(sin(alpha+PI/2.0)*5.0),
             100 + round(cos(alpha)*75.0),
             100 + round(sin(alpha)*75.0), FOREGROUND);
      alpha := (flt(start_time.hour)+flt(start_time.minute)/60.0-3.0) * PI / 6.0;
      lineTo(100 + round(cos(alpha-PI/2.0)*7.0),
             100 + round(sin(alpha-PI/2.0)*7.0),
             100 + round(cos(alpha)*50.0),
             100 + round(sin(alpha)*50.0), FOREGROUND);
      lineTo(100 + round(cos(alpha+PI/2.0)*7.0),
             100 + round(sin(alpha+PI/2.0)*7.0),
             100 + round(cos(alpha)*50.0),
             100 + round(sin(alpha)*50.0), FOREGROUND);
      fcircle(100, 100, 7, CLOCKCOLOR);
      circle(100, 100, 7, FOREGROUND);
      DRAW_FLUSH;
      await(start_time + 1 . SECONDS);
      command := busy_getc(KEYBOARD);
    end while;
  end func;
