-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmandelbrot.pas
110 lines (91 loc) · 2.07 KB
/
mandelbrot.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
unit mandelbrot;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, mwindows, threads;
type TMandelthread=class (TThread)
private
protected
procedure Execute; override;
public
Constructor Create(CreateSuspended : boolean);
end;
var man:TWindow=nil;
implementation
constructor TMandelthread.create(CreateSuspended : boolean);
begin
FreeOnTerminate := True;
inherited Create(CreateSuspended);
end;
procedure TMandelthread.execute;
// from the Ultibo forum, changed to work in window;
const cxmin = -2.5;
cxmax = 1.5;
cymin = -1.0;
cymax = 1.0;
maxiteration = 255;
escaperadius = 2;
var ixmax :Word;
iymax :Word;
ix, iy :Word;
cx, cy :real;
pixelwidth :real;
pixelheight :real;
colour : Byte;
zx, zy :real;
zx2, zy2 :real;
iteration : integer;
er2 : real = (escaperadius * escaperadius);
begin
if man=nil then
begin
man:=TWindow.create(1024,600,'Mandelbrot');
man.decoration.hscroll:=false;
man.decoration.vscroll:=false;
man.resizable:=false;
man.cls(0);
man.move(300,400,960,600,0,0);
end;
ixmax:=960;
iymax:=600;
pixelheight:= (cymax - cymin) / iymax;
pixelwidth:= pixelheight;
ThreadSetpriority(ThreadGetCurrent,6);
sleep(1);
for iy := 1 to iymax do
begin
cy := cymin + (iy - 1)*pixelheight;
if abs(cy) < pixelheight / 2 then cy := 0.0;
for ix := 1 to ixmax do
begin
cx := cxmin + (ix - 1)*pixelwidth;
zx := 0.0;
zy := 0.0;
zx2 := zx*zx;
zy2 := zy*zy;
iteration := 0;
while (iteration < maxiteration) and (zx2 + zy2 < er2) do
begin
zy := 2*zx*zy + cy;
zx := zx2 - zy2 + cx;
zx2 := zx*zx;
zy2 := zy*zy;
iteration := iteration + 1;
end;
if iteration = maxiteration then
begin
colour := 0;
end
else
begin
colour := iteration;
end;
man.putpixel(ix-1, iy-1, colour);
end;
end;
ThreadSetpriority(ThreadGetCurrent,3);
repeat sleep(100) until man.needclose;
man.destroy;
man:=nil;
end;
end.