ginput and sliders/slider callback

7 visualizaciones (últimos 30 días)
D B
D B el 9 de Mayo de 2014
Hi there! I have written a code to produce a fern leaf fractal...which is great but I'd like it to be able to zoom in! My goal is to create a slider function that zooms in on a particular point (that is picked by the users mouse), then use the slider to zoom in or out on the particular point.
At this point I would even be happy having it just be able to zoom with the slider.
I have googled, looked at other code, to no avail.
I know I need to create a slider_cb but I'm not even too sure as to how it relates and what it is trying to call.
Anyone think they can help??
Here is where I am at so far...
function main()
shg
clf reset
set(gcf,'color','white','menubar','none', ...
'numbertitle','off','name','Fractal Fern');
a=-3;
b=3;
c=0;
d=10;
x = [.5; .5];
kh = plot(x(1),x(2),'.');
treegreen = [3/5 2/3 1/8];
set(kh,'markersize',1,'color',treegreen,'erasemode','none');
axis([a b c d]);
axis off
%stop button with random color....oooh fancy
stop = uicontrol('style','toggle','string','stop', ...
'background',rand(1,3));
drawnow
h = [ .85 .92 .99 1.00];
A1 = [ .85 .04; -.04 .85]; b1 = [0; 1.6];
A2 = [ .20 -.26; .23 .22]; b2 = [0; 1.6];
A3 = [-.15 .28; .26 .24]; b3 = [0; .44];
A4 = [ 0 0 ; 0 .16];
%sets count
cnt = 1;
%create the fractal
%here we use elseif statements to plot points
start_slider(1)
while ~get(stop,'value');
r = rand;
if r < h(1);
x = A1*x + b1;
elseif r < h(2);
x = A2*x + b2;
elseif r < h(3);
x = A3*x + b3;
else
x = A4*x;
end
set(kh,'xdata',x(1),'ydata',x(2));
drawnow
cnt = cnt + 1;
end
%stop then close
set(stop,'style','pushbutton','string','close','callback','close (gcf)')
end
%
%START SLIDER
%
function start_slider(fignum)
smin = 0;
smax = 10;
slider_step = [(smax-smin)/100 0.1];
s0 = 0;
h = uicontrol(fignum,'style','Slider','Value',s0);
set(h,'Min',smin,'Max',smax,'position',[50 8 500 20]);
set(h,'Callback',@slider_cb);
set(h,'sliderstep',slider_step); %Default : [0.01 0.1];
set(h,'Value',s0);
% slider_cb(h,[]);
lh = addlistener(h,'ContinuousValueChange',@slider_cb);
while(waitforbuttonpress)
% This will continuously update the plot as the slider is moved.
end
end
function slider_cb(slider_handle,event_data)
val = get(slider_handle,'Value');
fprintf('value = %12.4f\n',val);
end

Respuestas (0)

Categorías

Más información sobre Data Exploration en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by