-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTricorn.m
More file actions
69 lines (51 loc) · 1.76 KB
/
Tricorn.m
File metadata and controls
69 lines (51 loc) · 1.76 KB
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
function V = Tricorn(n, resolution, varargin)
% Generelized Tricorn
% This function produces generelized Tricorn fractals by using conj(z)^n
% in its iteration rather than conj(z)^2.
% n: For the usual Tricorn, n = 2
% resolution: The number of points in the grid at every dimension
% Optional parameters
% fig: Set to true if you want the result to be plotted (default false)
% gpu: Calculation will happen on gpu (default false)
% flat: Set to true to make all data points either 0 or 1. (default false)
p = inputParser;
addParameter(p, 'fig', false, @islogical);
addParameter(p, 'gpu', true, @islogical);
addParameter(p, 'flat', true, @islogical);
if n >= 0
addParameter(p, 'ylimit', [-1.25, 1.25], @isnumeric);
addParameter(p, 'xlimit', [-1.25, 1.25], @isnumeric);
elseif n < 0
addParameter(p, 'ylimit', [-1.55, 1.55], @isnumeric);
addParameter(p, 'xlimit', [-1.55, 1.55], @isnumeric);
end
parse(p, varargin{:})
fig = p.Results.fig;
gpu = p.Results.gpu;
flat = p.Results.flat;
ylimit = p.Results.ylimit;
xlimit = p.Results.xlimit;
[X, Y] = meshgrid(linspace(xlimit(1), xlimit(2), resolution), ...
linspace(ylimit(1), ylimit(2), resolution));
if gpu
V = gather(arrayfun(@compute, n*ones(resolution), gpuArray(X), gpuArray(Y), resolution*ones(resolution)));
else
V = arrayfun(@(x, y)compute(n, x, y, resolution), X, Y);
end
V(V ~= max(V, [], 'all') & flat) = 0;
V(V ~= 0 & flat) = 1;
if fig
imagesc(V);
colormap("pink");
axis off;
end
function counter = compute(n, x, y, resolution)
z0 = complex(x, y);
z = z0;
counter = 1/resolution;
while counter <= 1 && abs(z) <= 2
z = conj(z)^n + z0;
counter = counter + 1/(resolution + 1);
end
end
end