Фрактал - геометрическая фигура, обладающая свойством самоподобия, то есть составленная из нескольких частей, каждая из которых подобна всей фигуре целиком. В математике под фракталами понимают множества точек в евклидовом пространстве, имеющие дробную метрическую размерность (в смысле Минковского или Хаусдорфа), либо метрическую размерность, отличную от топологической.
1. Кривая Госпера
Program Gosper_Curve;
Uses CRT, GraphABC;
Procedure Draw(x, y, l, u : Real; t, q : Integer);
Procedure Draw2(Var x, y: Real; l, u : Real; t, q : Integer);
Begin
Draw(x, y, l, u, t, q);
x := x + l*cos(u);
y := y - l*sin(u)
End;
Begin
If t > 0 Then
Begin
If q = 1 Then
Begin
x := x + l*cos(u);
y := y - l*sin(u);
u := u + pi
End;
u := u - 2*pi/19;
l := l/sqrt(7);
Draw2(x, y, l, u, t-1, 0);
Draw2(x, y, l, u+pi/3, t-1, 1);
Draw2(x, y, l, u+pi, t-1, 1);
Draw2(x, y, l, u+2*pi/3, t-1, 0);
Draw2(x, y, l, u, t-1, 0);
Draw2(x, y, l, u, t-1, 0);
Draw2(x, y, l, u-pi/3, t-1, 1)
End
Else
Line(Round(x), Round(y), Round(x + cos(u)*l), Round(y -sin(u)*l))
End;
Begin
SetWindowCaption('Фракталы: Кривая Госпера');
SetWindowSize(650,500);
ClearWindow;
Draw(100, 355, 400, 0, 4, 0);
Repeat Until KeyPressed
End.
Procedure Draw(x, y, l, a: Real);
Begin
If l > 4 Then
Begin
Rect(Round(x), Round(y), Round(l), a);
Draw(x - l*sin(a), y - l * cos(a), l / sqrt(2), a + pi / 4);
Draw(
x - l * sin(a) + l / sqrt(2) * cos(a + pi/4),
y - l * cos(a) - l / sqrt(2) * sin(a + pi/4),
l / sqrt(2),
a - pi/4)
End
End;
Begin
SetWindowCaption('Фракталы: Дерево Пифагора');
SetWindowSize(730,500);
ClearWindow;
Draw(280, 460, 100, 0);
Repeat Until KeyPressed
End.
procedure Draw(x, y, l, u : Real; t : Integer);
procedure Draw2(Var x, y: Real; l, u : Real; t : Integer);
begin
Draw(x, y, l, u, t);
x := x + l*cos(u);
y := y - l*sin(u);
end;
begin
if t > 0 then
begin
l := l/3;
Draw2(x, y, l, u, t-1);
Draw2(x, y, l, u+pi/3, t-1);
Draw2(x, y, l, u-pi/3, t-1);
Draw2(x, y, l, u, t-1);
end
else
Line(Round(x), Round(y), Round(x+cos(u)*l), Round(y-sin(u)*l))
end;
begin
SetWindowSize(425,500);
SetWindowCaption('Фракталы: Снежинка Коха');
Draw(10, 354, 400, pi/3, 5);
Draw(410, 354, 400, pi, 2);
Draw(210, 8, 400, -pi/3, 4);
end.
5. Множество Мандельброта
program Mandelbrot;
uses GraphABC;
const
n=255;
max=10;
var
x,y,x1,y1,cx,cy: real;
i,ix,iy: integer;
// z=z^2+c
begin
SetWindowSize(400,300);
SetWindowCaption('Фракталы: множество Мандельброта');
for ix:=0 to WindowWidth-1 do
for iy:=0 to WindowHeight-1 do
begin
x:=0;
y:=0;
cx:=0.002*(ix-720);
cy:=0.002*(iy-150);
for i:=1 to n do
begin
x1:=x*x-y*y+cx;
y1:=2*x*y+cy;
if (x1>max) or (y1>max) then break;
x:=x1;
y:=y1;
end;
if i>=n then SetPixel(ix,iy,clRed)
else SetPixel(ix,iy,RGB(255,255-i,255-i));
end;
end.