unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls, ComCtrls;

type
  TForm1 = class(TForm)
    Image1: TImage;
    Button1: TButton;
    TrackBar1: TTrackBar;
    Label1: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure TrackBar1Change(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;


implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
 Label1.Caption := 'Iteration count: '+inttostr(TrackBar1.Position);
 randomize;
 
 // kép inicalizalasa
 image1.Picture.Bitmap.PixelFormat := pf24bit;
 image1.Picture.Bitmap.width:=256;
 image1.Picture.Bitmap.height:=256;
 image1.Picture.Bitmap.Canvas.Brush.Color := clBlack;
 image1.Picture.Bitmap.Canvas.FillRect(image1.Picture.Bitmap.Canvas.ClipRect);
end;

procedure TForm1.Button1Click(Sender: TObject);
 type
  PRGBArray = ^TRGBArray;
  TRGBArray = Array[0..1000000] of TRGBTriple;
 var rx,ry,x,y,i:integer;
     c:byte;
     P   : PRGBArray;
     max,radius:extended;
     h:array[0..255] of array[0..255] of extended;
     pd,disp:extended;
begin
 // heightmap nullázása
 for y:=0 to 255 do
  for x:=0 to 255 do
   h[x,y] := 0;

 // heightmap feltoltése a körök algoritmussal az adott iteracioval
 max := 0;
 disp:=10;
 for i:=1 to TrackBar1.Position do begin
  rx:=random(256);
  ry:=random(256);
  radius:= random(100)+30;
  for y:=0 to 255 do begin
   for x:=0 to 255 do begin
    pd := (sqrt(sqr(x-rx)+sqr(y-ry))*2) / radius;
    if abs(pd) <= 1 then
     h[x,y] := h[x,y] +5+ cos(pd*PI)*5;
    if h[x,y]>max then max := h[x,y];
   end;
  end;
 end;

 // heightmap megjelenitese
 for y:=0 to 255 do begin
  P := image1.Picture.Bitmap.ScanLine[y];
  for x:=0 to 255 do begin
   p[x].rgbtRed := round( (h[x,y]/max)*255 );
   p[x].rgbtGreen := round( (h[x,y]/max)*255 );
   p[x].rgbtBlue := round( (h[x,y]/max)*255 );
  end;
 end;
 image1.Repaint;
end;

procedure TForm1.TrackBar1Change(Sender: TObject);
begin
 Label1.Caption := 'Iteration count: '+inttostr(TrackBar1.Position);
end;

end.
