Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Лекция Фрактальная графика.doc
Скачиваний:
34
Добавлен:
04.12.2018
Размер:
840.19 Кб
Скачать

Вариации на тему кривой Коха

Три копии кривой Коха, расположенные на сторонах правильного треугольника, образуют замкнутую кривую, называемую снежинкой Коха.

Построение можно производить на сторонах квадрата.

Снежинка Коха представляет собой линию бесконечной длины, ограничивающую конечную площадь.

program Koch1;

uses CRT, Graph;

var

gd, gm: Integer;

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

gd := Detect;

InitGraph(gd, gm, 'c:\bp\bgi');

Draw(410, 10, 400, -pi, 4);

Draw(10, 410, 400, 0, 4);

Draw(10, 10, 400, -pi/2, 4);

Draw(410, 410, 400, pi/2, 4);

ReadKey;

CloseGraph

end.

program Koch2;

uses CRT, Graph;

var

gd, gm: Integer;

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

gd := Detect;

InitGraph(gd, gm, 'c:\bp\bgi');

Draw(210, 8, 400, -2*pi/3, 4);

Draw(10, 354, 400, 0, 4);

Draw(410, 354, 400, 2*pi/3, 4);

ReadKey;

CloseGraph

end.

program Koch3;

uses CRT, Graph;

var

gd, gm: Integer;

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

gd := Detect;

InitGraph(gd, gm, 'c:\bp\bgi');

Draw(10, 354, 400, pi/3, 4);

Draw(410, 354, 400, pi, 4);

Draw(210, 8, 400, -pi/3, 4);

ReadKey;

CloseGraph

end.

Снежинку Коха Можно получить используя следующие СИФ (формат FRACTINT):

Island_Koch {

0.333 0.000 0.000 0.333 -0.006 7.325 0.084

-0.167 0.288 -0.288 -0.167 2.013 3.823 0.083

-0.167 -0.288 0.288 -0.167 -2.031 3.816 0.083

0.167 0.288 -0.288 0.167 2.031 6.136 0.084

-0.333 0.000 0.000 -0.333 0.006 2.651 0.083

0.167 -0.288 0.288 0.167 -2.025 6.153 0.083

0.333 0.000 0.000 0.333 -0.006 1.325 0.084

0.167 0.288 -0.288 0.167 -3.177 3.148 0.083

-0.167 0.288 -0.288 -0.167 -3.183 6.823 0.083

-0.333 0.000 0.000 -0.333 -0.006 8.651 0.084

0.167 -0.288 0.288 0.167 3.159 3.165 0.083

-0.167 -0.288 0.288 -0.167 3.177 6.804 0.083

}

или

Island_Koch_2 {

0.333 0.000 0.000 0.333 -1.998 6.785 0.110

0.333 0.000 0.000 0.333 -1.998 -0.139 0.110

0.333 0.000 0.000 0.333 1.998 -0.139 0.110

0.333 0.000 0.000 0.333 1.998 6.785 0.110

0.333 0.000 0.000 0.333 -3.978 3.317 0.110

0.333 0.000 0.000 0.333 4.002 3.317 0.110

0.502 -0.290 0.290 0.502 1.452 2.442 0.340

}