- /
-
Juila set
on 3 Dec 2023
- 6
- 17
- 0
- 0
- 1061
drawframe(1);
Write your drawframe function below
function drawframe(f)
originalResolution = 400; % Original resolution
downscaledResolution = 200; % Downscaled resolution
maxIterationsArray = (linspace(sqrt(10), sqrt(1420), 48)).^2;
complexParameter = -0.744 + 0.148i;
juliaImage = computeJuliaSet(originalResolution, maxIterationsArray(f), complexParameter);
colorMap = parula;
rgbImage = ind2rgb(juliaImage, colorMap);
finalImage = imresize(rgbImage, [downscaledResolution, downscaledResolution], 'method', 'bilinear');
imshow(finalImage);
function iterationCounts = computeJuliaSet(resolution, maxIter, complexParam)
%%
% A function to compute the Julia set values.
%%
xRange = [-0.5, 0.5];
yRange = [-0.5, 0.5];
% Create complex grid
yValues = linspace(xRange(1), xRange(2), resolution);
xValues = linspace(yRange(1), yRange(2), resolution);
[gridX, gridY] = meshgrid(xValues, yValues);
complexGrid = complex(gridX, gridY);
% Initialize iteration count array
iterationCounts = zeros(resolution);
% Logical array for convergence check
isConverging = true(resolution);
for i = 1:maxIter
currentlyDiverging = false(resolution);
complexGrid(isConverging) = complexGrid(isConverging).^2 + complexParam;
currentlyDiverging(isConverging) = abs(complexGrid(isConverging)) > 5;
iterationCounts(currentlyDiverging) = i;
isConverging = ~currentlyDiverging & isConverging;
end
end
end