PDA

View Full Version : آموزش: رسم فرکتال Julia



مصطفی ساتکی
یک شنبه 01 خرداد 1390, 08:34 صبح
معادله رسم a=a*a+c می باشد.

unit Unit1;

interface

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

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}
const N = 500;
N2 = 250;
Scale = 1.5;
type TComplex = record
re : Double;
im : Double;
end;
function AddComplex(a,b : TComplex): TComplex;
begin
Result.re := a.re + b.re;
Result.im := a.im + b.im;

end;

function MulComplex(a,b : TComplex): TComplex;
begin
Result.re := a.re * b.re - a.im * b.im;
Result.im := a.re * b.im + a.im * b.re;

end;

function MagnitudeComplex(a : TComplex): Double;
begin
Result := sqr(a.re) + sqr(a.im);
end;

procedure SetComplex(var a : TComplex;re ,im : Double);
begin
a.re := re;
a.im := im;
end;
function Julia(x,y : Integer): Integer;
var a ,c : TComplex;
i : Integer;
jx,jy : Double;
begin
jx := scale* (x - n2)/N2;
jy := scale*(y - n2)/N2;
SetComplex(a,jx,jy);
SetComplex(c,-0.8,0.156);
Result := 1;
for i := 0 to 200-1 do
begin
a := AddComplex( MulComplex(a,a),c);
if MagnitudeComplex(a) > 1000 then
begin
Result := 0;
Break;
end;
end;

end;

procedure DrawJulia(Bit : TBitmap);
var x ,y : Integer;
p : PByte;
value : integer;
begin
for y := 0 to Bit.Height-1 do
begin
p := Bit.ScanLine[y];
for x := 0 to Bit.Width-1 do
begin
p^ := Julia(x,y)*255;
value := p^;
inc(p);
if value > 0 then
p^ := y div 2
else p^ :=0;
inc(p);
if value >0 then
p^ := x div 2
else p^ :=0;
inc(p);
end;

end;

end;

procedure TForm1.Button1Click(Sender: TObject);
var Bit : TBitmap;
begin
Bit := TBitmap.Create;
with Bit do
begin
PixelFormat := pf24bit;
Width := N;
Height := N;
end;
DrawJulia(Bit);
Canvas.Draw(0,0,Bit);
end;

end.

EhsanVB6
چهارشنبه 01 تیر 1390, 11:55 صبح
با سلام به Delphi_CAT عزیز،
درصورت تمایل برای همکاری در انجام پروژه پردازش تصویر لطفا با ایمیل بنده تماس بگیرید: s_sangi@mehr.sharif.edu
با تشکر