Subversion Repositories svnkaklik

Rev

Blame | Last modification | View Log | Download

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, OleCtrls, VCFI, Menus;

type
  TForm1 = class(TForm)
    vykreslit: TButton;
    Button2: TButton;
    reset: TButton;
    vypis: TButton;
    Obrazovka: TPaintBox;
    Posuv: TScrollBar;
    ScrollBar2: TScrollBar;
    ScrollBar3: TScrollBar;
    zoom: TScrollBar;
    StaticText1: TStaticText;
    procedure vykreslitClick(Sender: TObject);

    procedure obrazovkaShow(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure resetClick(Sender: TObject);
    procedure vypisClick(Sender: TObject);
    procedure ScrollBar2Change(Sender: TObject);
    procedure ScrollBar3Change(Sender: TObject);
    procedure zoomChange(Sender: TObject);
    procedure PosuvChange(Sender: TObject);
    procedure Button1Click(Sender: TObject);

   private
    { Private declarations }
  public
procedure smazat;
    { Public declarations }
  end;

const
  MAX=455;
  pametMAX=6*MAX;
var
  Form1: TForm1;
  PobrazovkaYMIN: array [0..MAX] of word;
  PobrazovkaYMAX: array [0..MAX] of word;
  pamet: array[0..pametMAX{,0..pametMAX}]of word;

implementation

uses Unit2;

{$R *.dfm}

procedure Tform1.smazat;
begin
  Form1.Canvas.Pen.Mode:=pmNop;

  Form1.Obrazovka.Canvas.Brush.Color:=clblack;
  Form1.Obrazovka.Canvas.Rectangle(0,0,455,256);
  Form1.Obrazovka.Canvas.Pen.Color:=cllime;
end;

procedure Draw;
var
 x: word;
begin

  Form1.Obrazovka.Canvas.MoveTo(0,PobrazovkaYMAX[0]);
  for x:=1 to MAX do
  begin
    Form1.Obrazovka.Canvas.LineTo(x,PobrazovkaYMAX[x]);
    Form1.Obrazovka.Canvas.LineTo(x,PobrazovkaYMIN[x]);
  end
end;

procedure TForm1.vykreslitClick(Sender: TObject);
  (*  ble:extended;*)
var i,x: integer;
begin

  smazat;
  for x:=0 to pametMAX do
   begin
     pamet[x]:=random(200); //round((sin(x/1)*100)+100);
   end;
  PosuvChange(Self);
end;


procedure TForm1.obrazovkaShow(Sender: TObject);
begin
  smazat;
end;

procedure TForm1.Button2Click(Sender: TObject);
var n: integer;
begin
  n:=0;
  while n<256 do
  begin
    Obrazovka.Canvas.Pen.Color:=clYellow;
    Obrazovka.Canvas.MoveTo(0,n);
    Obrazovka.Canvas.LineTo(455,n);
    n:=n+70;
  end;
  n:=0;
  while n<455 do
  begin
    Obrazovka.Canvas.Pen.Color:=clSilver;
    Obrazovka.Canvas.MoveTo(n,0);
    Obrazovka.Canvas.LineTo(n,455);
    n:=n+70;
  end;
  Obrazovka.Canvas.Pen.Color:=cllime
end;

procedure TForm1.resetClick(Sender: TObject);
var j:word;
begin
  smazat;
  for j:=0 to MAX do
  PobrazovkaYMIN[j]:=0;
  PobrazovkaYMAX[j]:=0;
  for j:=0 to pametMAX do
  pamet[j]:=0;
end;

procedure TForm1.vypisClick(Sender: TObject);
var faut:TextFile;
    x:word;
    ble: string;
begin
  Form2.ShowModal;
  if Form2.Edit1.Text<>'' then
  begin
    AssignFile(faut,Form2.Edit1.Text);
    Rewrite(faut);

    for x:=0 to 455 do
    begin
      str(x,ble);
      Write(faut,'x='+ble+',');
      str(PobrazovkaYMIN[x],ble);
      Write(faut,'Ymin='+ble+',');
      str(PobrazovkaYMAX[x],ble);
      Writeln(faut,'Ymax='+ble+'; ');
    end;
    CloseFile(faut);
  end
end;


procedure TForm1.ScrollBar2Change(Sender: TObject);
 var
   xold:word;
   zoom: integer;
   code: integer;
begin
  xold:=ScrollBar2.Position;

  Obrazovka.Canvas.Pen.Color:=clred;
  Obrazovka.Canvas.Pen.Mode:=pmNotXor;
  Form1.Obrazovka.Canvas.MoveTo(xold,Obrazovka.Height);
  Form1.Obrazovka.Canvas.LineTo(xold,0);

end;

procedure TForm1.ScrollBar3Change(Sender: TObject);
var
  x,y:word;
begin
  obrazovka.Canvas.Pen.Color:=clred;
  obrazovka.Canvas.Pen.Mode:=pmNotXor;
  Form1.obrazovka.Canvas.MoveTo(0,ScrollBar3.Position);
  Form1.obrazovka.Canvas.LineTo(obrazovka.Width,ScrollBar3.Position);
  obrazovka.Canvas.Pen.Mode:=pmNop;
end;

procedure TForm1.zoomChange(Sender: TObject);
var
  zoom, Xpamet, Xobraz, i, Ymax, Ymin : word;
begin
  zoom:=Form1.zoom.Position;
  Xpamet:=Posuv.Position;

  Xobraz:=0;
  while Xpamet < pametMAX do
  begin
    Ymax:=pamet[Xpamet];
    Ymin:=pamet[Xpamet];
    for i:=Xpamet to Xpamet+(zoom-1) do
      begin
        if pamet[Xpamet]<Ymin then Ymin:=pamet[Xpamet]
          else if pamet[Xpamet]>Ymax then Ymax:=pamet[Xpamet]
      end;
  end;
  smazat;
  Draw;
end;

procedure TForm1.PosuvChange(Sender: TObject);
begin
  Posuv.Max:=pametMAX-MAX;
  zoomChange(Self);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
 smazat;
end;

end.