Filter löschen
Filter löschen

zooming in and out mandelbrot figure

2 Ansichten (letzte 30 Tage)
Gregory Power
Gregory Power am 10 Mai 2019
Kommentiert: Gregory Power am 10 Mai 2019
Hi all,
I am writing a script that needs to call a function that draws a mandelbrot figure. The script also needs to be able to zoom in on pixels selected by a left mouse click input and receneter on the pixel. the right mouse button sound zoom out. Clicking the middle button is supposed to break the loop. I think I have the loop while loop right and my mandelbrot function works, I am just not sure about what to put in the parentheses’ for xl, xlen, yl, and ylen in the beginning. below is my script and my mandelbrot function... any help would be appreciated
%zooming script
close all %closes all figures and images
clc %clears the command window
%% calls madelbrot function and assigns values to the valiables used in the while loop
mandelbrot %calls madelbrot function to start process
button=0; %assigns a space for the mousr input
zlevel=1; %assigns a space for the zoom level
xl=get( ,'xlim');
xlen= size( ,2); %creates array to store xlen values
yl=get( ,'ylim');
ylen=size( ,1); %creates array to store xlen values
while button~=2 %loop to run zooming of mandelbrot figure
%the ~= means that the loop will as long as the input is
%either the left button or the right button is pressed
%% button selection and zooming if elsif
[x,y,button]=ginput(1); %user input from mouse.
%the 1 assigns only one click input
if button==1 % Left mouse button input
zlevel=zlevel*2; %zooms in on the pixel clicked
zoom(2); %zooms in
elseif button==2 %right mouse button input
zlevel=zlevel/2; %decreases the zoom level
if zlevel<1 %Ensures that ther is no zoom level less than 1
zlevel=1;
end
zoom(0.5); %zooms out
else % last option in if/elseif. gives a final option
break %if any other input is selected, the loop breaks
end
%% reassigns axis limits around button click location
xlimit=[x-xlen/zlevel/2+0.5 x+xlen/zlevel/2+0.5]; %creates centered x-axis on click point
%reassigns the limits
%of the x-axis
if xlimit(1)<0.5
xlimit=[0.5 xlen/zlevel+0.5];
end
if xlimit(2)>0.5+xlen
xlimit=[xlen-xlen/zlevel+0.5 xlen+0.5];
end
xlim(xlimit); %sets the length of xlim
ylimit=[y-ylen/zlevel/2+0.5 y+ylen/zlevel/2+0.5]; %creates centered y-axis on click point
%reassigns the limits of the y-axis
if ylimit(1)<0.5
ylimit=[0.5 ylen/zlevel+0.5];
end
if ylimit(2)>0.5+ylen
ylimit=[ylen-ylen/zlevel+0.5 ylen+0.5];
end
ylim(ylimit); %sets the length of ylim
end
  1 Kommentar
Gregory Power
Gregory Power am 10 Mai 2019
Here is my mandelbrot function
function mandelbrot
% Mandelbrot set fractal
% ouput image resolution, WIDTHxHEIGHT
W = 100; %number of points in x axis
H = 100; %number of points in y axis
% fractal x y range
ymin = -0.5;
ymax = 0.5;
xmin = -2;
xmax = 0;
% maximum number of iterations
interation_max = 1000;
% Generate linearly spaced points from X_MIN to X_MAX
x = linspace(xmin, xmax, W);
% Generate linearly spaced points from Y_MIN to Y_MAX
y = linspace(ymin, ymax, H);
% Create a linear 2d grid
% X is 2d a array, column value are varying and row values are constant
% Y is 2d a array, row value are varying and column values are constant
[X, Y] = meshgrid(x, y);
% Allocate space for output
zval = zeros(H, W);
xn = 0;
yn = 0;
xnew = 0;
ynew = 0;
a = 0;
b = 0;
nPoints = W * H;
for m = 1:nPoints
a = X(m);
b = Y(m);
xn = 0;
yn = 0;
k = 1;
while (k <= interation_max) && ((xn^2+yn^2) < 4)
xnew = xn^2 - yn^2 + a;
ynew = 2*xn*yn + b;
xn = xnew;
yn = ynew;
k = k+1;
end
zval(m) = k;
end
cmap = flipud(jet(interation_max));
colormap(cmap);
image(x,y,zval); %show image
end

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by