📄 fractal_explorer.m
字号:
function varargout = fractal_explorer(varargin)
% FRACTAL_EXPLORER - Chaos, Lindenmayer Systems, Strange Attractors and
% more...
%
% CSE Fractal Explorer is a GUI-based program for exploring and studying the
% most common form of fractals, chaotic systems and fractional dimension systems.
% An overview of the features with a small introductory text is available at
% http://ltcmail.ethz.ch/cavin/fractals.html
%
% The usage is strightforward. Type "fractal_explorer", and the main window
% will be opened and the Mandelbrot Set will be drawn. All features are available
% via menus and buttons. Information is given on the bottom-left corner of the
% figure, while tips and information will appear on the left side of the figure
% when user input is required/possible.
%
% The features include:
% - Logistic Equation [1]
% - Real 2D Attractors:
% - Henon Attractor [1]
% - Pickover System [1]
% - Arbitrary Quadratic Map [1]
% - Real 3D Attractors:
% - Lorenz Attractor [2]
% - Roessler Attractor [2]
% - Limited Quadratic Map [2]
% - Complex Maps:
% - Mandelbrot Set [1,5]
% - Julia Sets [1,3,5]
% - Arbitrary Polynomial Newton-Raphson Attraction Basins [1,5]
% - Barnsley's Tree [1,5]
% - Arbitrary Mandelbrot and Julia-based Sets [1,5]
% - Quaterions:
% - Mandelbrot and Julia Sets [2]
% - String Systems:
% - Lindemayer Systems Single Rule
% - Lindenmayer Systems Multiple-Rules
% - Plant-like systems:
% - Barbsley's Fern [4,6]
% - Fractal Trees
% - 3D Systems
% - 3D-Multiple-Rules Lindenmayer Systems [2]
% - Menger Sponge [2,4]
% - Folded Plans:
% - Mesh grids [2]
% - Fractals Clouds
% - Fractal Landscapes [2]
%
% Notes:
% [1] Interactive Zooming
% [2] Interactive 3-D View
% [3] Julia explorer with on-the-fly previews
% [4] Limited to built-in parameters
% [5] Include the function Make-It-3D!
% [6] Equations taken from Brian Mearns's "Fractal Fern"
% http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=4372&objectType=file
%
% For most functions, dialogs will allow introducing user-defined parameters or
% equations for the calculation. Most dialog contains a button labeled "Cool Params" -
% this will propose a set of parameters leading to a chaotic behavior (as it is
% sometimes difficult to find a good parameter set); when only one "good" set of
% parameter is known, it will be given by default the first time the function is called.
%
% Written by L.Cavin, 30.07.2004, (c) CSE
% This code is free to use and modify for non-commercial purposes.
% Web address: http://ltcmail.ethz.ch/cavin/fractals.html#SOFT
% FOLLOWS THE STANDARD GUIDE COMMENTS:
%
% FRACTAL_EXPLORER M-file for fractal_explorer.fig
% FRACTAL_EXPLORER, by itself, creates a new FRACTAL_EXPLORER or raises the existing
% singleton*.
%
% H = FRACTAL_EXPLORER returns the handle to a new FRACTAL_EXPLORER or the handle to
% the existing singleton*.
%
% FRACTAL_EXPLORER('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in FRACTAL_EXPLORER.M with the given input arguments.
%
% FRACTAL_EXPLORER('Property','Value',...) creates a new FRACTAL_EXPLORER or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before fractal_explorer_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to fractal_explorer_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help fractal_explorer
% Last Modified by GUIDE v2.5 28-Jul-2004 15:29:22
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @fractal_explorer_OpeningFcn, ...
'gui_OutputFcn', @fractal_explorer_OutputFcn, ...
'gui_LayoutFcn', @fractal_explorer_LayoutFcn, ...
'gui_Callback', []);
if nargin & isstr(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before fractal_explorer is made visible.
function fractal_explorer_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to fractal_explorer (see VARARGIN)
% Choose default command line output for fractal_explorer
if nargin > 3
disp('unknown input arguments:');
varargin{:}
end
handles.output = hObject;
axes(handles.main_axis);
gridsize = get(handles.main_axis, 'position');
handles.gridsize = gridsize(3);
handles.space = get_mandelbrot_initial(handles.gridsize);
handles.main_image = image(handles.space);
axis(handles.main_axis, 'off');
% CANCELLING INACTIVE MENU ITEMS
set(handles.menu_rabinovich, 'Enable', 'off');
handles.xmin = -2;
handles.xmax = 1;
handles.ymin = -1.5;
handles.ymax = 1.5;
handles.itern = 70;
handles.mode = 1; % mandelbrot
handles.xjul = 0;
handles.yjul = 0;
handles = fillupdescription(handles);
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes fractal_explorer wait for user response (see UIRESUME)
% uiwait(handles.fractal_explorer);
% --- Outputs from this function are returned to the command line.
function varargout = fractal_explorer_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in button_cancel.
function button_cancel_Callback(hObject, eventdata, handles)
% hObject handle to button_cancel (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.button_3D, 'Enable', 'on');
delete(handles.preview_image);
set(handles.txt_zoom_1, 'Visible', 'off');
set(handles.txt_zoom_2, 'Visible', 'off');
set(handles.button_cancel, 'Visible', 'off');
set(handles.button_compute, 'Visible', 'off');
set(handles.preview_axis, 'Visible', 'off');
axes(handles.main_axis);
% --- Executes on button press in button_compute.
function button_compute_Callback(hObject, eventdata, handles)
% hObject handle to button_compute (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
axes(handles.main_axis);
set(handles.button_3D, 'Enable', 'on');
scaling = sqrt((handles.xmax - handles.xmin)/(handles.txmax - handles.txmin));
if scaling > 0
scaling = scaling /2;
end
handles.xmin = handles.txmin;
handles.xmax = handles.txmax;
handles.ymin = handles.tymin;
handles.ymax = handles.tymax;
if ~isfield(handles, 'grain')
handles.grain = 1;
elseif isempty(handles.grain)
handles.grain = 1;
end
switch handles.mode
case -1 % logistic
handles.space = compute_logistic(handles.xmin, handles.xmax, handles.ymin, handles.ymax, handles.itern, handles.gridsize, 1);
case 1 % mandelbrot
handles.itern = handles.itern * scaling;
handles.space = compute_mandelbrot_real(handles.xmin, handles.xmax, handles.ymin, handles.ymax, handles.itern, handles.gridsize, 1);
case 2 % julia
handles.itern = handles.itern * scaling;
handles.space = compute_julia(handles.xmin, handles.xmax, handles.ymin, handles.ymax, handles.xjul, handles.yjul, handles.itern, handles.gridsize, 1);
case 3 % newton
handles.space = compute_newton(handles.xmin, handles.xmax, handles.ymin, handles.ymax, handles.itern, handles.gridsize/handles.grain, 1);
case 4 % user newton
handles.space = compute_newton_power(handles.xmin, handles.xmax, handles.ymin, handles.ymax, handles.itern, handles.gridsize/handles.grain, handles.ctes, 1);
case 5 % barnsley
handles.space = compute_barnsley(handles.xmin, handles.xmax, handles.ymin, handles.ymax, handles.xjul, handles.yjul, handles.itern, handles.gridsize, 1);
case 6 % circu poly
if handles.arbitrary_mode == 1
handles.space = compute_circumpoly(handles.xmin, handles.xmax, handles.ymin, handles.ymax, handles.xjul, handles.yjul, handles.itern, handles.gridsize/handles.grain, 1);
else
handles.space = compute_arbitrary(handles.equation, handles.xmin, handles.xmax, handles.ymin, handles.ymax, handles.xjul, handles.yjul, handles.itern, handles.gridsize/handles.grain, 1);
end
otherwise
warning('CSE:Fractals:Render', 'Unknown Mode');
end
if isfield(handles, 'main_image')
try delete(handles.main_image); end
end
handles = fillupdescription(handles);
if handles.mode > 0
handles.main_image = image(handles.space, 'EraseMode', 'none');
axis(handles.main_axis, 'off');
else % we have an [x y] in handles.space, not a complete table with handles.space(x, y) = color
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]);
end
try delete(handles.preview_image); end
set(handles.txt_zoom_1, 'Visible', 'off');
set(handles.txt_zoom_2, 'Visible', 'off');
set(handles.button_cancel, 'Visible', 'off');
set(handles.button_compute, 'Visible', 'off');
set(handles.preview_axis, 'Visible', 'off');
% Update handles structure
guidata(hObject, handles);
% --------------------------------------------------------------------
function menu_head_program_Callback(hObject, eventdata, handles)
% hObject handle to menu_head_program (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function menu_help_Callback(hObject, eventdata, handles)
% hObject handle to menu_help (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%% UNTIL RELEASE, THIS FUNCTION IS USED FOR TESTING NEW ALGORITHMS %%
% return;
%% UNTIL RELEASE, THIS FUNCTION IS USED FOR TESTING NEW ALGORITHMS %%
helpmsg = sprintf(['CSE Fractals III\n\nA cross-platform matlab port from the Macintosh Software CSE Fractals II.\n\n' ...
'Select in the menus the different types of fractals, according to which type of ' ...
'"numbers" are used in the computation: Real, Imaginary, Quaternions, String Systems.\n\n' ...
'More information of the different types of fractals is available on the internet. ' ...
'Click on "More Info..." to go to a web-page with background infos avout chaos.']);
answr = questdlg(helpmsg, 'CSE Fractals III', 'More Info...', 'OK', 'OK');
if strcmp(answr, 'More Info...')
% web('\\sust43\d$\cavin\Documents\web\fractals.html', '-browser');
web('http://ltcmail.ethz.ch/cavin/fractals.html', '-browser');
end
% --------------------------------------------------------------------
function menu_quit_Callback(hObject, eventdata, handles)
% hObject handle to menu_quit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
delete(handles.fractal_explorer);
% --------------------------------------------------------------------
function menu_mandelbrot_whole_Callback(hObject, eventdata, handles)
% hObject handle to menu_mandelbrot_whole (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles.space = get_mandelbrot_initial(handles.gridsize);
handles.main_image = image(handles.space, 'EraseMode', 'none');
axis(handles.main_axis, 'off');
handles.xmin = -2;
handles.xmax = 1;
handles.ymin = -1.5;
handles.ymax = 1.5;
handles.itern = 70;
handles.mode = 1; % mandelbrot
handles = fillupdescription(handles);
set(handles.menu_julia_mouse, 'Enable', 'on'); % enables julia.
% Update handles structure
guidata(hObject, handles);
% --------------------------------------------------------------------
function menu_mandelbrot_user_Callback(hObject, eventdata, handles)
% hObject handle to menu_mandelbrot_user (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
msg = sprintf('Mandelbrot Set:\n\nDefine Region and iterations:\n\n');
tmp = {num2str(handles.xmin), num2str(handles.xmax), num2str(handles.ymin), num2str(handles.ymax), num2str(handles.itern)};
tmp = localdlg({[msg 'Real Minimum:'], 'Real Maximum:', 'Imaginary Minimum:', 'Imaginary Maximum:', 'Iterations:'}, 'Mandelbrot Set', [1 10], tmp);
if isempty(tmp)
return;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -