Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Mandelbrot - GestoreDelForm.pas

GestoreDelForm.pas

Caricato da: Poggi Marco
Scarica il programma completo

  1. unit GestoreDelForm;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  7.   Dialogs, grafica, ExtCtrls, StdCtrls, unit1;
  8.  
  9. type vetEstremi = array [1..2] of pointf;
  10.  
  11. type
  12.   TForm1 = class(TForm)
  13.     ButtonVistaTotale: TButton;
  14.     LabelPosizioneDelPuntatore: TLabel;
  15.     ImageFoglio: TImage;
  16.     procedure FormOnCreate(Sender: TObject);
  17.     procedure ImageFoglioOnMouseMove(Sender: TObject; Shift: TShiftState;
  18.       X, Y: Integer);
  19.     procedure ImageFoglioOnMouseDown(Sender: TObject; Button: TMouseButton;
  20.       Shift: TShiftState; X, Y: Integer);
  21.     procedure ImageFoglioOnMouseDownUp(Sender: TObject;
  22.       Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  23.     procedure ButtonVistaTotaleClick(Sender: TObject);
  24.   private
  25.     { Déclarations privées }
  26.     foglio:ttavola;
  27.     estremi:vetEstremi;
  28.     tinta:TColore;
  29.     procedure VistaGlobale;
  30.     procedure Traccia;
  31.   public
  32.     { Déclarations publiques }
  33.   end;
  34.  
  35. var
  36.   Form1: TForm1;
  37.  
  38. implementation
  39.  
  40. uses Unit2, Unit3;
  41.  
  42. {$R *.dfm}
  43.  
  44. procedure TForm1.FormOnCreate(Sender: TObject);
  45. begin
  46.   self.Text:='Mandelbrot';
  47.   tinta.Crea;
  48.   VistaGlobale;
  49.   Traccia;
  50. end;
  51.  
  52. procedure TForm1.VistaGlobale;
  53. begin
  54.   estremi[1].x:=-2.0;
  55.   estremi[1].y:=-2.0;
  56.   estremi[2].x:=2.0;
  57.   estremi[2].y:=2.0;
  58.   foglio:=ttavola.crea(ImageFoglio.Canvas, estremi[1].x, estremi[1].y, estremi[2].x);
  59. end;
  60.  
  61. procedure TForm1.Traccia;
  62. var punto, x0:pointf;
  63.     passo,xTemp:double;
  64.     iterazioni, fineIterazioni:integer;
  65. begin
  66.   punto:=estremi[1];
  67.   passo:=(estremi[2].x - estremi[1].x) / 650.0;
  68.   fineIterazioni:=tinta.maxColore;
  69.   while punto.x < estremi[2].x do
  70.   begin
  71.      punto.y:=estremi[1].y;
  72.      while punto.y < estremi[2].y do
  73.      begin
  74.          iterazioni:=0;
  75.          x0.x:=0.0;
  76.          x0.y:=0.0;
  77.          while ((x0.x*x0.x + x0.y*x0.y) < 4.0) and
  78.                 (iterazioni < fineIterazioni) do
  79.          begin
  80.             xtemp:=x0.x*x0.x - x0.y*x0.y;
  81.             x0.y:=2.0 * x0.x * x0.y;
  82.             x0.x:=xtemp;
  83.  
  84.             x0.x:=x0.x + punto.x;
  85.             x0.y:=x0.y + punto.y;
  86.  
  87.             iterazioni:=iterazioni + 1;
  88.          end;
  89.          if (iterazioni < fineIterazioni) then
  90.          begin
  91.             foglio.tinta:=tinta.calcolaColore(iterazioni);
  92.          end
  93.          else
  94.          begin
  95.             foglio.tinta:=0;
  96.          end;
  97.          foglio.punto(punto);
  98.          punto.y:=punto.y + passo;
  99.      end;
  100.      punto.x:=punto.x + passo;
  101.   end;
  102. end;
  103.  
  104. procedure TForm1.ImageFoglioOnMouseMove(Sender: TObject;
  105.   Shift: TShiftState; X, Y: Integer);
  106. var coordinate, esito:pointf;
  107. begin
  108.   coordinate.x:=X;
  109.   coordinate.y:=Y;
  110.   esito:=foglio.deTraslamento(coordinate);
  111.   LabelPosizioneDelPuntatore.Caption:=Format('(%12.10f | %12.10f)',
  112.                                              [esito.x, esito.y]);
  113. end;
  114.  
  115. procedure TForm1.ImageFoglioOnMouseDown(Sender: TObject;
  116.   Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  117. var coordinate:pointf;
  118. begin
  119.    coordinate.x:=X;
  120.    coordinate.y:=Y;
  121.    estremi[1]:=foglio.deTraslamento(coordinate);
  122. end;
  123.  
  124. procedure TForm1.ImageFoglioOnMouseDownUp(Sender: TObject;
  125.   Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  126. var coordinate:pointf;
  127.     xtemp,delta:double;
  128. begin
  129.    coordinate.x:=X;
  130.    coordinate.y:=Y;
  131.    estremi[2]:=foglio.deTraslamento(coordinate);
  132.    if estremi[1].x > estremi[2].x then
  133.    begin
  134.       xtemp:=estremi[1].x;
  135.       estremi[1].x:=estremi[2].x;
  136.       estremi[2].x:=xtemp;
  137.    end;
  138.    delta:=estremi[2].x - estremi[1].x;
  139.    if delta > 2e-11 then
  140.    begin
  141.       estremi[2].y:=estremi[1].y + delta;
  142.       foglio.Free;
  143.       foglio:=ttavola.crea(ImageFoglio.Canvas,
  144.                         estremi[1].x, estremi[1].y, estremi[2].x);
  145.       Traccia;
  146.    end
  147.    else
  148.    begin
  149.      Application.MessageBox('   Impossibile ingrandire oltre. ', 'Attenzione', MB_OK);
  150.    end;
  151. end;
  152.  
  153. procedure TForm1.ButtonVistaTotaleClick(Sender: TObject);
  154. begin
  155.   VistaGlobale;
  156.   Traccia;
  157. end;
  158.  
  159. end.