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

📄 fractal_explorer.m

📁 Fractal Explorer GUI-based program for exploring and studying the most common form of fractals, c
💻 M
📖 第 1 页 / 共 5 页
字号:
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',[-4 4],'YLim',[-4 4], ...
    '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.6 0.6 1], ...
    'Marker','.', ...
    'LineStyle', 'none', ...
    'markersize',1, ...
    'erase','none', ...
    'xdata',[],'ydata',[]);
lne_trace=line( ...
    'color',[0.3 0.3 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 = handles.ctes(1)+handles.ctes(2)*x+handles.ctes(3)*x^2+handles.ctes(4)*x*y+handles.ctes(5)*y+handles.ctes(6)*y^2;
        y = handles.ctes(7)+handles.ctes(8)*x+handles.ctes(9)*x^2+handles.ctes(10)*x*y+handles.ctes(11)*y+handles.ctes(12)*y^2;
        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_3d_quadratic_Callback(hObject, eventdata, handles)
% hObject    handle to menu_3d_quadratic (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

ctes = {'-0.9265', '-0.3559', '1.1407', '0.7124', '0.6284', '2.3291';
    '-0.5979', '2.1002', '1.9831', '-0.4003', '-0.9395', '-0.7943';
    '-0.9442', '-0.2482', '1.3302', '2.2930', '0.0177', '1.6679';
    '1.6619', '-0.5615', '-0.7754', '-0.3045', '-0.1223', '0.0075';
    '-0.2470', '0.7607', '-0.8069', '2.4585', '1.0668', '2.7723';
    '-0.6662', '0.1314', '1.3999', '-0.7810', '0.9384', '2.9119';
    '1.4158', '0.5323', '0.1181', '0.2789', '-0.8468', '-0.3616';
    '-0.1649', '-0.0193', '-0.8416', '2.5414', '-0.8609', '1.4893';
    '-0.9246', '1.5296', '0.9030', '1.4218', '1.5015', '0.7241'
    '-0.8783', '0.7726', '-0.1282', '1.0554', '0.5411', '0.9502'};
%uiwait(msgbox('Sorry, this feature is not working properly yet.', 'CSE Warning', 'modal'));
msg = sprintf('3D Quadratic Map:\n\nIterations on the system:\nx = a+ bx+ cx^2+ dxy+ ey+ fy^2\ny = x\nz = y\n\nSpecify the constants:\n\n');
if ~isfield(handles, 'quad3d_params')
    handles.quad3d_params = {ctes{unidrnd(length(ctes)), :}};
elseif isempty(handles.quad3d_params)
    handles.quad3d_params = {ctes{unidrnd(length(ctes)), :}};
end
handles.quad3d_params = localdlg({[msg 'a:'], 'b:', 'c:', 'd:', 'e:', 'f:'}, '3D Quadratic Map', [1 10], handles.quad3d_params, ...
    ['usrdta = get(gcbf, ''UserData''); z = unidrnd(length(usrdta.Data)); for i=1:length(usrdta.EditHandles), '...
        'set(usrdta.EditHandles(i), ''String'', str2num(usrdta.Data{z,i})); end;'], 'Cool Params', ctes);
if isempty(handles.quad3d_params)
    return;
end
for i = 1:length(handles.quad3d_params)
    handles.ctes(i) = str2num(handles.quad3d_params{i});
end
handles.mode = -6;
x = 0.1000001;
y = -0.1000001;
z = 1.0000001;
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.\nPress ''n'' to randomize the parameters.'));
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',[-2 2],'YLim',[-2 2],'ZLim',[-2 2], ...
    'XTick',[],'YTick',[],'ZTick',[], ...
    'Drawmode','fast', ...
    'Visible','on', ...
    'NextPlot','add', ...
    'Color', [0 0 0], ...
    'View',[145, -14]); % [-49,16]
xlabel('X');
ylabel('Y');
zlabel('Z');
serie = [x y z; zeros(3999, 3)];
lne_head = line( ...
    'color','r', ...
    'Marker','.', ...
    'LineStyle', 'none', ...
    'markersize',25, ...
    'erase','xor', ...
    'xdata',serie(1),'ydata',serie(2),'zdata',serie(3));
lne_body = line( ...
    'color','y', ...
    'Marker','.', ...
    'markersize',1, ...
    'LineStyle', 'none', ...
    'erase','none', ...
    'xdata',[],'ydata',[],'zdata',[]);
lne_tail=line( ...
    'color',[0.3 0.3 1], ...
    'Marker','.', ...
    'markersize',1, ...
    'LineStyle', 'none', ...
    'erase','none', ...
    'xdata',[],'ydata',[],'zdata',[]);
lne_trace=line( ...
    'color','b', ...
    'Marker','.', ...
    'markersize',1, ...
    'LineStyle', 'none', ...
    'erase','none', ...
    'xdata',[],'ydata',[],'zdata',[]);
lne_dust=line( ...
    'color',[0 0 0.5], ...
    'Marker','.', ...
    'markersize',1, ...
    'LineStyle', 'none', ...
    'erase','none', ...
    'xdata',[],'ydata',[],'zdata',[]);

rotate3d on;
x_old = 0; y_old = 0; z_old = 0;
set(handles.fractal_explorer, 'CurrentCharacter', '?);
cchr = get(handles.fractal_explorer, 'CurrentCharacter');
while strcmp(get(handles.fractal_explorer, 'CurrentCharacter'), cchr)
    x_ld = x_old; y_ld = y_old; z_ld = z_old;
    x_old = x; y_old = y; z_old = z;
    xx = handles.ctes(1)+handles.ctes(2)*x+handles.ctes(3)*x^2+handles.ctes(4)*x*y+handles.ctes(5)*y+handles.ctes(6)*y^2;
    z = y;
    y = x;
    x = xx;
    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;
    if abs(x) > 10 | abs(y) > 10 | abs(z) > 10 | strcmp(get(handles.fractal_explorer, 'CurrentCharacter'), 'n') | ...
            (abs(x-x_old)<1e-5 & abs(y-y_old)<1e-5 & abs(z-z_old)<1e-5) | (abs(x-x_ld)<1e-5 & abs(y-y_ld)<1e-5 & abs(z-z_ld)<1e-5)
%         uiwait(msgbox(sprintf('This map is not chaotic but divergent.\nStopping calculation.'), 'CSE Info', 'modal'));
%         set(handles.fractal_explorer, 'CurrentCharacter', '?);
		for i = 1:length(handles.quad3d_params)
            handles.ctes(i) = unifrnd(-1, 3);
		end
		x = 0.1000001;
		y = -0.1000001;
		z = 1.0000001;
		handles = fillupdescription(handles);
        hold off;
		set(handles.main_axis, 'Drawmode','normal');
		plot3(0, 0, 0, 'k.', 'MarkerSize', 1);
		set(handles.main_axis, ...
            'XLim',[-2 2],'YLim',[-2 2],'ZLim',[-2 2], ...
            'XTick',[],'YTick',[],'ZTick',[], ...
            'Drawmode','fast', ...
            'Visible','on', ...
            'NextPlot','add', ...
            'Color', [0 0 0], ...
            'View',[145, -14]); % [-49,16]
		xlabel('X');
		ylabel('Y');
		zlabel('Z');
		serie = [x y z; zeros(3999, 3)];
		lne_head = line( ...
            'color','r', ...
            'Marker','.', ...
            'markersize',25, ...
            'LineStyle', 'none', ...
            'erase','xor', ...
            'xdata',serie(1),'ydata',serie(2),'zdata',serie(3));
		lne_body = line( ...
            'color','y', ...
            'Marker','.', ...
            'markersize',1, ...
            'LineStyle', 'none', ...
            'erase','none', ...
            'xdata',[],'ydata',[],'zdata',[]);
		lne_tail=line( ...
            'color',[0.3 0.3 1], ...
            'Marker','.', ...
            'markersize',1, ...
            'LineStyle', 'none', ...
            'erase','none', ...
            'xdata',[],'ydata',[],'zdata',[]);
		lne_trace=line( ...
            'color','b', ...
            'Marker','.', ...
            'markersize',1, ...
            'LineStyle', 'none', ...
            'erase','none', ...
            'xdata',[],'ydata',[],'zdata',[]);
		lne_dust=line( ...
            'color',[0 0 0.5], ...
            'Marker','.', ...
            'markersize',1, ...
            'LineStyle', 'none', ...
            'erase','none', ...
            'xdata',[],'ydata',[],'zdata',[]);
		rotate3d on;
        set(handles.fractal_explorer, 'CurrentCharacter', cchr);
    end
end
hold off;
set(handles.fractal_explorer, 'KeyPressFcn', '');
set(handles.txt_help, 'Visible', 'off');
guidata(hObject, handles);

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


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


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

ctes = {'F' 'f' 'YF+XF+Y' 'XF-YF-X' '1.0472' 'YF' '8';
    'F' 'f' 'XF+F+XF-F-F-XF-F+F+F-F+F+F-X' 'XF+F+XF+F+XF+F' '1.0472' 'Y' '5';
    'F' 'f' 'X+YF+' '-FX-Y' '1.5708' 'FX' '10';
    'F' 'f' 'XF-F+F-XF+F+XF-F+F-X' 'Y' '1.5708' 'F+XF+F+XF' '5';};
msg = sprintf('Multiple Rules Lindenmayer Systems:\n\nGrammar:\nF: Draw Line;f: Forward (no draw)\nX,Y: Do nothing\n+,-: change x-angle;\n\n');
if ~isfield(handles, 'multi_lin_params')
    handles.multi_lin_params = {ctes{unidrnd(size(ctes, 1)), :}};
elseif isempty(handles.multi_lin_params)
    handles.multi_lin_params = {ctes(unidrnd(size(ctes, 1)), :)};
end
handles.multi_lin_params = localdlg({[msg 'F->'], 'f->', 'X->', 'Y->', 'Angle:', 'Intial String:', 'Iterations:'}, 'Lindenmayer Systems', [1 20], handles.multi_lin_params, ...
    ['usrdta = get(gcbf, ''UserData''); z = unidrnd(size(usrdta.Data, 1)); for i=1:length(usrdta.EditHandles), '...
        'set(usrdta.EditHandles(i), ''String'', usrdta.Data{z,i}); end;'], 'Cool Params', ctes);
if isempty(handles.multi_lin_params)
    return;
end
unit = 1;
unit_factor = 1/4;
rules(1).code = 'F';
rules(1).replace = handles.multi_lin_params{1};
rules(2).code = 'f';
rules(2).replace = handles.multi_lin_params{2};
rules(3).code = 'X';
rules(3).replace = handles.multi_lin_params{3};
rules(4).code = 'Y';
rules(4).replace = handles.multi_lin_params{4};
alpha = str2num(handles.multi_lin_params{5});
lin_string = handles.multi_lin_params{6};
m_iter = round(str2num(handles.multi_lin_params{7}));
handles.mode = -10;

handles.lindenrules = '';
for i = 1:length(rules)
    handles.lindenrules = [handles.lindenrules rules(i).code '->' rules(i).replace '\n'];
end
graphic_rules(1).code = 'F';
graphic_rules(1).type = 0;
graphic_rules(1).style = 'y-';
graphic_rules(2).code = '+';
graphic_rules(2).type = 2;
graphic_rules(2).value = -alpha;
graphic_rules(3).code = '-';
graphic_rules(3).type = 2;
graphic_rules(3).value = alpha;
graphic_rules(4).code = 'f';
graphic_rules(4).type = 1;
graphic_rules(5).code = 'X';
graphic_rules(5).type = -1;
graphic_rules(6).code = 'Y';
graphic_rules(6).type = -1;
handles = fillupdescription(handles);
set(gcf,'Pointer','watch');
axes(handles.main_axis);
for i = 1:m_iter
   [lin_string, overflow] = expand_string(lin_string, rules);
   if overflow
 

⌨️ 快捷键说明

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