⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fractal_explorer.m

📁 Fractal Explorer GUI-based program for exploring and studying the most common form of fractals, c
💻 M
📖 第 1 页 / 共 5 页
字号:



% --------------------------------------------------------------------
function menu_logistic_Callback(hObject, eventdata, handles)
% hObject    handle to menu_logistic (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

handles.xmin = 1;
handles.xmax = 4;
handles.ymin = 0;
handles.ymax = 1;
handles.itern = 20;
handles.mode = -1;
handles.space = compute_logistic(handles.xmin, handles.xmax, handles.ymin, handles.ymax, handles.itern, handles.gridsize, 1);
if isfield(handles, 'main_image')
    try delete(handles.main_image); end
end
handles.main_image = plot(handles.space(:,1), handles.space(:,2), 'b.', 'MarkerSize', 1);
axis(handles.main_axis, [handles.xmin handles.xmax handles.ymin handles.ymax]);

set(handles.menu_julia_mouse, 'Enable', 'off'); % disable julia

handles = fillupdescription(handles);

guidata(hObject, handles);

% --------------------------------------------------------------------
function menu_head_attractors_Callback(hObject, eventdata, handles)
% hObject    handle to menu_head_attractors (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% --------------------------------------------------------------------
function menu_rabinovich_Callback(hObject, eventdata, handles)
% hObject    handle to menu_rabinovich (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


msg = sprintf('Rabinovich-Fabrikant:\n\nIterations on the system:\ndx/dt = a*(y-x)\ndy/dt = x*(b-z)-y\ndz/dt = x*y-c*z\n\nSpecify the constants:\n\n');
if ~isfield(handles, 'rabinovich_params')
    handles.rabinovich_params = {'0.87', '1.1'};
elseif isempty(handles.rabinovich_params)
    handles.rabinovich_params = {'0.87', '1.1'};
end
handles.rabinovich_params = localdlg({[msg 'a:'], 'b:'}, 'Rabinovich-Fabrikant', [1 10], handles.rabinovich_params);
if isempty(handles.rabinovich_params)
    return;
end
for i = 1:length(handles.rabinovich_params)
    handles.ctes(i) = str2num(handles.rabinovich_params{i});
end
handles.mode = -7;
x = 0.0000001;
y = -0.0000001;
z = 0.0000001;
dt = 0.01;
set(handles.fractal_explorer, 'KeyPressFcn', ';');
handles = fillupdescription(handles);
set(handles.txt_help, 'String', sprintf('Press any key to stop.\nUse the mouse to modify the\nobservation angle in 3 dimensions.'));
set(handles.txt_help, 'Visible', 'on');
axes(handles.main_axis);
if isfield(handles, 'main_image')
    try delete(handles.main_image); end
end

set(handles.main_axis, 'Drawmode','normal');
plot3(0, 0, 0, 'k.', 'MarkerSize', 1);
set(handles.main_axis, ...
    'XLim',[-400 400],'YLim',[-400 400],'ZLim',[-100 500], ...
    'XTick',[],'YTick',[],'ZTick',[], ...
    'Drawmode','fast', ...
    'Visible','on', ...
    'NextPlot','add', ...
    'Color', [0 0 0], ...
    'View',[-49,16]);
xlabel('X');
ylabel('Y');
zlabel('Z');
serie = [x y z; zeros(3999, 3)];
lne_head = line( ...
    'color','r', ...
    'Marker','.', ...
    'markersize',25, ...
    'erase','xor', ...
    'xdata',serie(1),'ydata',serie(2),'zdata',serie(3));
lne_body = line( ...
    'color','y', ...
    'LineStyle','-', ...
    'erase','none', ...
    'xdata',[],'ydata',[],'zdata',[]);
lne_tail=line( ...
    'color',[0.3 0.3 1], ...
    'LineStyle','-', ...
    'erase','none', ...
    'xdata',[],'ydata',[],'zdata',[]);
lne_trace=line( ...
    'color','b', ...
    'LineStyle','-', ...
    'erase','none', ...
    'xdata',[],'ydata',[],'zdata',[]);
lne_dust=line( ...
    'color',[0 0 0.5], ...
    'LineStyle','-', ...
    'erase','none', ...
    'xdata',[],'ydata',[],'zdata',[]);

rotate3d on;
set(handles.fractal_explorer, 'CurrentCharacter', '?);
cchr = get(handles.fractal_explorer, 'CurrentCharacter');
while strcmp(get(handles.fractal_explorer, 'CurrentCharacter'), cchr)
    dx = y*(z-1-x^2)+handles.ctes(1)*x;
    dy = x*(3*z+1-x^2)+handles.ctes(1)*y;
    dz = -2*z*(handles.ctes(2)+x*y);
    x = x + dx*dt;
    y = y + dy*dt;
    z = z + dz*dt;
    serie = [x y z; serie(1:end-1,:)];
    set(lne_trace,'xdata',serie(500:end-2, 1),'ydata',serie(500:end-2, 2),'zdata',serie(500:end-2, 3));
    set(lne_dust,'xdata',serie(end-1:end, 1),'ydata',serie(end-1:end, 2),'zdata',serie(end-1:end, 3));
    set(lne_tail,'xdata',serie(41:499, 1),'ydata',serie(41:499, 2),'zdata',serie(41:499, 3));
    set(lne_head,'xdata',serie(1,1),'ydata',serie(1, 2),'zdata',serie(1, 3));
    set(lne_body,'xdata',serie(1:40,1),'ydata',serie(1:40,2),'zdata',serie(1:40,3));
    drawnow;
end
hold off;
set(handles.fractal_explorer, 'KeyPressFcn', '');
set(handles.txt_help, 'Visible', 'off');
guidata(hObject, handles);



% --------------------------------------------------------------------
function menu_lorenz_Callback(hObject, eventdata, handles)
% hObject    handle to menu_lorenz (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

msg = sprintf('Lorenz Attractor:\n\nIterations on the system:\ndx/dt = a*(y-x)\ndy/dt = x*(b-z)-y\ndz/dt = x*y-c*z\n\nSpecify the constants:\n\n');
if ~isfield(handles, 'lorenz_params')
    handles.lorenz_params = {'10', '28', '2.85'};
elseif isempty(handles.lorenz_params)
    handles.lorenz_params = {'10', '28', '2.85'};
end
handles.lorenz_params = localdlg({[msg 'a:'], 'b:', 'c:'}, 'Lorenz Attractor', [1 10], handles.lorenz_params);
if isempty(handles.lorenz_params)
    return;
end
for i = 1:length(handles.lorenz_params)
    handles.ctes(i) = str2num(handles.lorenz_params{i});
end
handles.mode = -2;
x = unifrnd(-10, 20); %0.1000001;
y = unifrnd(-10, 20); %-0.1000001;
z = unifrnd(10, 30); %1.0000001;
dt = 0.01;
set(handles.fractal_explorer, 'KeyPressFcn', ';');
handles = fillupdescription(handles);
set(handles.txt_help, 'String', sprintf('Press any key to stop.\nUse the mouse to modify the\nobservation angle in 3 dimensions.\n(inspired by Mathworks'' Lorenz Demo)'));
set(handles.txt_help, 'Visible', 'on');
axes(handles.main_axis);
if isfield(handles, 'main_image')
    try delete(handles.main_image); end
end

set(handles.main_axis, 'Drawmode','normal');
plot3(0, 0, 0, 'k.', 'MarkerSize', 1);
set(handles.main_axis, ...
    'XLim',[-40 40],'YLim',[-40 40],'ZLim',[-10 50], ...
    'XTick',[],'YTick',[],'ZTick',[], ...
    'Drawmode','fast', ...
    'Visible','on', ...
    'NextPlot','add', ...
    'Color', [0 0 0], ...
    'View',[-180, -4]); % [-49,16]
xlabel('X');
ylabel('Y');
zlabel('Z');
serie = [x y z; zeros(3999, 3)];
lne_head = line( ...
    'color','r', ...
    'Marker','.', ...
    'markersize',25, ...
    'erase','xor', ...
    'xdata',serie(1),'ydata',serie(2),'zdata',serie(3));
lne_body = line( ...
    'color','y', ...
    'LineStyle','-', ...
    'erase','none', ...
    'xdata',[],'ydata',[],'zdata',[]);
lne_tail=line( ...
    'color',[0.8 0.8 1], ...
    'LineStyle','-', ...
    'erase','none', ...
    'xdata',[],'ydata',[],'zdata',[]);
lne_trace=line( ...
    'color',[0.4 0.4 1], ...
    'LineStyle','-', ...
    'erase','none', ...
    'xdata',[],'ydata',[],'zdata',[]);
lne_dust=line( ...
    'color',[0.2 0.2 1], ...
    'LineStyle','-', ...
    'erase','none', ...
    'xdata',[],'ydata',[],'zdata',[]);

rotate3d on;
set(handles.fractal_explorer, 'CurrentCharacter', '?);
cchr = get(handles.fractal_explorer, 'CurrentCharacter');
while strcmp(get(handles.fractal_explorer, 'CurrentCharacter'), cchr)
    dx = dt*handles.ctes(1)*(y-x);
    dy = dt*((handles.ctes(2)-z)*x-y);
    dz = dt*(x*y-handles.ctes(3)*z);
    x = x + dx;
    y = y + dy;
    z = z + dz;
    serie = [x y z; serie(1:end-1,:)];
    set(lne_trace,'xdata',serie(500:end-2, 1),'ydata',serie(500:end-2, 2),'zdata',serie(500:end-2, 3));
    set(lne_dust,'xdata',serie(end-1:end, 1),'ydata',serie(end-1:end, 2),'zdata',serie(end-1:end, 3));
    set(lne_tail,'xdata',serie(41:499, 1),'ydata',serie(41:499, 2),'zdata',serie(41:499, 3));
    set(lne_head,'xdata',serie(1,1),'ydata',serie(1, 2),'zdata',serie(1, 3));
    set(lne_body,'xdata',serie(1:40,1),'ydata',serie(1:40,2),'zdata',serie(1:40,3));
    drawnow;
end
hold off;
set(handles.fractal_explorer, 'KeyPressFcn', '');
set(handles.txt_help, 'Visible', 'off');
guidata(hObject, handles);


% --------------------------------------------------------------------
function menu_henon_Callback(hObject, eventdata, handles)
% hObject    handle to menu_henon (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

msg = sprintf('Henon Attractor:\n\nIterations on the system:\nx = y-a-b*x^2\ny = c*x\n\nSpecify the constants:\n\n');
if ~isfield(handles, 'henon_params')
    handles.henon_params = {'1', '1.4', '0.3'};
elseif isempty(handles.henon_params)
    handles.henon_params = {'1', '1.4', '0.3'};
end
handles.henon_params = localdlg({[msg 'a:'], 'b:', 'c:'}, 'Henon Attractor', [1 10], handles.henon_params);
if isempty(handles.henon_params)
    return;
end
for i = 1:length(handles.henon_params)
    handles.ctes(i) = str2num(handles.henon_params{i});
end
handles.mode = -3;
x = unifrnd(-0.5, 0.5); %0.1000001;
y = unifrnd(-0.2, 0.2); %-0.1000001;
set(handles.fractal_explorer, 'KeyPressFcn', ';');
set(handles.menu_julia_mouse, 'Enable', 'off'); % disable julia
handles = fillupdescription(handles);
set(handles.txt_help, 'String', sprintf('Press any key to stop.\nTo zoom in during the calculation,\nselect a zone with the mouse.\nTo zoom out, right-click.'));
set(handles.txt_help, 'Visible', 'on');
axes(handles.main_axis);
if isfield(handles, 'main_image')
    try delete(handles.main_image); end
end

set(handles.main_axis, 'Drawmode','normal');
plot(0, 0, 'k.', 'MarkerSize', 1);
set(handles.main_axis, ...
    'XLim',[-1.5 1.5],'YLim',[-0.5 0.5], ...
    'XTick',[],'YTick',[], ...
    'Drawmode','fast', ...
    'Visible','on', ...
    'NextPlot','add', ...
    'Color', [0 0 0]);
xlabel('X');
ylabel('Y');
serie = [x y; zeros(9999, 2)];
lne_body = line( ...
    'color','y', ...
    'Marker','.', ...
    'LineStyle', 'none', ...
    'markersize',1, ...
    'erase','none', ...
    'xdata',[],'ydata',[]);
lne_tail=line( ...
    'color',[0.5 0.5 1], ...
    'Marker','.', ...
    'LineStyle', 'none', ...
    'markersize',1, ...
    'erase','none', ...
    'xdata',[],'ydata',[]);
lne_trace=line( ...
    'color',[0.2 0.2 1], ...
    'Marker','.', ...
    'LineStyle', 'none', ...
    'markersize',1, ...
    'erase','none', ...
    'xdata',[],'ydata',[]);

set(handles.fractal_explorer, 'CurrentCharacter', '?);
cchr = get(handles.fractal_explorer, 'CurrentCharacter');
zoom on;
while strcmp(get(handles.fractal_explorer, 'CurrentCharacter'), cchr)
    tmp = [];
    for i = 1:20
        xx = y+handles.ctes(1)-handles.ctes(2)*x^2;
        y = handles.ctes(3)*x;
        x = xx;
        tmp = [tmp; x y];
    end
    serie = [tmp; serie(1:end-20,:)];
    set(lne_trace,'xdata',serie(500:end-2, 1),'ydata',serie(500:end-2, 2));
    set(lne_tail,'xdata',serie(41:499, 1),'ydata',serie(41:499, 2));
    set(lne_body,'xdata',serie(1:40,1),'ydata',serie(1:40,2));
    drawnow;
end
hold off;
set(handles.fractal_explorer, 'KeyPressFcn', '');
set(handles.txt_help, 'Visible', 'off');
guidata(hObject, handles);

% --------------------------------------------------------------------
function menu_pickover_Callback(hObject, eventdata, handles)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -