• Remix
  • Share
  • New Entry

on 16 Nov 2023
  • 26
  • 40
  • 1
  • 0
  • 1913
drawframe(1);
Write your drawframe function below
function drawframe(f)
% DRAWFRAME Draw a frame visualising a Julia set.
%
% The set of complex points, z, that are non-divergent under
% successive mappings of the form z -> z^2 + c, where c is a
% complex constant, form a Julia set. This function draws a
% frame, numbered f, in an animation visualising how a Julia set
% changes as the phase of c is varied between 0 and 2pi.
%
% The code used here to determine whether a point in the complex plane
% belongs to a Julia set is based on the examples at:
% https://personalpages.manchester.ac.uk/staff/yanghong.huang/
% teaching/MATH36032/html/juliaset.html
% The strategy for the animation has been adapted from:
% https://isquared.digital/visualizations/2020-06-26-julia-set/
%
% For the visualisation, the mapping z -> z^2 + c is applied
% itMax times to each point within the region considered. A point is
% identified as divergent at iteration k <= itMax if its modulus
% exceeds zDiverged, and the point is assigned a value k-1.
% Non-divergent points are assigned a value of itMax.
%
% Changing parameter values at the beginning of the code, and
% changing the colormap used, can lead to a range of different
% visualisations.
%
% Other possibilities for animation include:
% - zooming in on the region considered;
% - a walk through of a region in the complex plane,
% especially for high zoom;
% - varying the number of iterations;
% - varying the modulus of the constant c;
% - varying the colormap.
% Frame geometry.
nFrame = 48;
xy1 = -1.5; xy2 = 1.5;
nxy = 300;
% Complex constant.
r = 1;
theta = f * 2 * pi / nFrame;
c = r * cos(theta) + 1i * r * sin(theta);
% Iiterations and divergence criterion.
itMax = 50;
zDiverged = 1;
% Grid of points in the complex plane.
x = linspace(xy1,xy2, nxy);
y = linspace(xy1, xy2, nxy);
[X,Y] = meshgrid(x,y);
Z = complex(X,Y);
C = ones(size(X))*c;
V = zeros(size(C));
for k = 1:itMax
Z = Z.^2 + C;
V = V + (abs(Z)<zDiverged);
end
% Visualise the Julia set.
imagesc(V);
colormap(hot);
axis off
end
Animation
Remix Tree