unit GestoreDelForm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, grafica, ExtCtrls, StdCtrls, unit1;
type vetEstremi = array [1..2] of pointf;
type
TForm1 = class(TForm)
ButtonVistaTotale: TButton;
LabelPosizioneDelPuntatore: TLabel;
ImageFoglio: TImage;
procedure FormOnCreate(Sender: TObject);
procedure ImageFoglioOnMouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Integer);
procedure ImageFoglioOnMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure ImageFoglioOnMouseDownUp(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure ButtonVistaTotaleClick(Sender: TObject);
private
{ Déclarations privées }
foglio:ttavola;
estremi:vetEstremi;
tinta:TColore;
procedure VistaGlobale;
procedure Traccia;
public
{ Déclarations publiques }
end;
var
Form1: TForm1;
implementation
uses Unit2, Unit3;
{$R *.dfm}
procedure TForm1.FormOnCreate(Sender: TObject);
begin
self.Text:='Mandelbrot';
tinta.Crea;
VistaGlobale;
Traccia;
end;
procedure TForm1.VistaGlobale;
begin
estremi[1].x:=-2.0;
estremi[1].y:=-2.0;
estremi[2].x:=2.0;
estremi[2].y:=2.0;
foglio:=ttavola.crea(ImageFoglio.Canvas, estremi[1].x, estremi[1].y, estremi[2].x);
end;
procedure TForm1.Traccia;
var punto, x0:pointf;
passo,xTemp:double;
iterazioni, fineIterazioni:integer;
begin
punto:=estremi[1];
passo:=(estremi[2].x - estremi[1].x) / 650.0;
fineIterazioni:=tinta.maxColore;
while punto.x < estremi[2].x do
begin
punto.y:=estremi[1].y;
while punto.y < estremi[2].y do
begin
iterazioni:=0;
x0.x:=0.0;
x0.y:=0.0;
while ((x0.x*x0.x + x0.y*x0.y) < 4.0) and
(iterazioni < fineIterazioni) do
begin
xtemp:=x0.x*x0.x - x0.y*x0.y;
x0.y:=2.0 * x0.x * x0.y;
x0.x:=xtemp;
x0.x:=x0.x + punto.x;
x0.y:=x0.y + punto.y;
iterazioni:=iterazioni + 1;
end;
if (iterazioni < fineIterazioni) then
begin
foglio.tinta:=tinta.calcolaColore(iterazioni);
end
else
begin
foglio.tinta:=0;
end;
foglio.punto(punto);
punto.y:=punto.y + passo;
end;
punto.x:=punto.x + passo;
end;
end;
procedure TForm1.ImageFoglioOnMouseMove(Sender: TObject;
Shift: TShiftState; X, Y: Integer);
var coordinate, esito:pointf;
begin
coordinate.x:=X;
coordinate.y:=Y;
esito:=foglio.deTraslamento(coordinate);
LabelPosizioneDelPuntatore.Caption:=Format('(%12.10f | %12.10f)',
[esito.x, esito.y]);
end;
procedure TForm1.ImageFoglioOnMouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var coordinate:pointf;
begin
coordinate.x:=X;
coordinate.y:=Y;
estremi[1]:=foglio.deTraslamento(coordinate);
end;
procedure TForm1.ImageFoglioOnMouseDownUp(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var coordinate:pointf;
xtemp,delta:double;
begin
coordinate.x:=X;
coordinate.y:=Y;
estremi[2]:=foglio.deTraslamento(coordinate);
if estremi[1].x > estremi[2].x then
begin
xtemp:=estremi[1].x;
estremi[1].x:=estremi[2].x;
estremi[2].x:=xtemp;
end;
delta:=estremi[2].x - estremi[1].x;
if delta > 2e-11 then
begin
estremi[2].y:=estremi[1].y + delta;
foglio.Free;
foglio:=ttavola.crea(ImageFoglio.Canvas,
estremi[1].x, estremi[1].y, estremi[2].x);
Traccia;
end
else
begin
Application.MessageBox(' Impossibile ingrandire oltre. ', 'Attenzione', MB_OK);
end;
end;
procedure TForm1.ButtonVistaTotaleClick(Sender: TObject);
begin
VistaGlobale;
Traccia;
end;
end.