Home » Fractals

# Category Archives: Fractals

## Ford Circles

clc; close all; fi = 0:0.01:2*pi;

```figure('Position',[0 0 500 500])
hold on;
for h =1:15
for k = 1:15
R  = 1/(2*k^2);
x  = h/k + R*sin(fi);
y  = 1/(2*k^2) + R*cos(fi);
plot(x,y,'k');
% Symmetric
y  = -(1/(2*k^2) + R*cos(fi));
plot(x,y,'k');
end
end
axis([0, 2.2,-1.1, 1.1 ]);axis off;```

## Dragon Fractal

clc; clear all; close all;

```a  = ones(1);
for i = 1:12
sz = size(a);
b  = a;
ind = ceil(sz(2)/2);
b(ind) = ~(b(ind));
sz = size(a);
a = [a,1,b];
end
st = 1; % Step
len = size(a);
x0 = 0; y0 = 0; %Initial
Lv = 0; % Looking along positive x axis
for i = 1:len(2)
x1 = x0 - sin(Lv)*st;
y1 = y0 + cos(Lv)*st;
if a(i) == 1
Lv = Lv + pi/2;
else
Lv = Lv - pi/2;
end
xv(i) = x1;
yv(i) = y1;
x0 = x1;
y0 = y1;
end```
```fig = figure('Position',[0 0 800 800]);
set(fig, 'color', [0 0 0]);
plot(xv,yv,'clipping','off')
axis off;```

## Box Fractals

clc; clear all; close all;

```a = 1;
figure('Position',[0 0 800 800])
for i = 1 :5
[n m] = size(a);
Z = zeros(n,m);
a = [a,Z,a;
a,a,a;
a,Z,a
];
end
imagesc(a);
colormap bone;axis off;
caxis([0, 1]);```

```clc; clear all;
a = 1;
figure('Position',[0 0 800 800])
for i = 1 :5
[n m] = size(a);
Z= zeros(n,m);
a = [Z,a,Z;
a,a,a;
Z,a,Z
];
end
imagesc(a);
colormap bone;axis off;
caxis([0, 1]);```

```clc; clear all;
a = 1;
figure('Position',[0 0 800 800])
for i = 1 :5
[n m] = size(a);
Z= zeros(n,m);
a = [a,a,a;
a,Z,a;
a,a,a
];
end
imagesc(a);
colormap bone;axis off;
caxis([0, 1]);```

```clc; clear all;
a = 1;
figure('Position',[0 0 800 800])
for i = 1 :5
[n m] = size(a);
Z= zeros(n,m);
a = [a,Z,a;
Z,a,Z;
a,Z,a
];
end
imagesc(a);
colormap bone;axis off;
caxis([0, 1]);

```
```clc; clear all;
a = 1;
figure('Position',[0 0 800 800])
for i = 1 :5
[n m] = size(a);
Z= zeros(n,m);
if mod(i,2) == 0
a = [Z,a,a;
a,a,a;
a,a,a
];
else
a = [a,a,a;
a,Z,a;
a,a,a
];
end
end
imagesc(a);
colormap bone;axis off;
caxis([0, 1]);```

## Carotid-Kundalini function

clc; clear all; close all;

```figure('Position',[0 0 800 800])
hold on;
x  = -1:0.005:1;
sz = size(x);
for n = 1:15
for i = 1:sz(2)
CK(i) = cos(n*x(i)*acos(x(i)));
end
plot(x,CK,'k');
axis off;
end```

Slightly modifing the Carotid-Kundalini function

```x  = -1:0.005:1;
sz = size(x);
for n = 1:25
for i = 1:sz(2)
for j = 1:sz(2)
CK(i,j) = cos(n*(x(i))*acos(x(i)))+...
cos(n*(x(j))*acos(x(j)));
end
end
end
figure('Position',[0 0 800 800])
imagesc(CK);
colormap bone;
axis off;```

## Butterfly Fractal

clc; clear all; close all;

```x  = -1:0.005:1;
sz = size(x);
a  = 0.05;
for i =1:sz(2)
for j = 1:sz(2)
bf(i,j) = ((x(i)^2-x(j)^2)*sin((x(i) + x(j))/a))/(x(i)^2 + x(j)^2);
end
end
fig = figure('Position',[0 0 800 800]);
imagesc(bf);
colormap bone;axis off;
set(fig, 'color', [0 0 0]);```