📄 fractal_explorer.m
字号:
end
handles.xmin = str2num(tmp{1});
handles.xmax = str2num(tmp{2});
handles.ymin = str2num(tmp{3});
handles.ymax = str2num(tmp{4});
handles.itern = str2num(tmp{5});
handles.mode = 1; % mandelbrot
handles = fillupdescription(handles);
set(handles.menu_julia_mouse, 'Enable', 'on'); % enables julia.
handles.space = compute_mandelbrot_real(handles.xmin, handles.xmax, handles.ymin, handles.ymax, handles.itern, handles.gridsize, 1);
handles.main_image = image(handles.space, 'EraseMode', 'none');
axis(handles.main_axis, 'off');
% Update handles structure
guidata(hObject, handles);
% --------------------------------------------------------------------
function menu_mandlebrot_Callback(hObject, eventdata, handles)
% hObject handle to menu_mandlebrot (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function menu_julia_mouse_Callback(hObject, eventdata, handles)
% hObject handle to menu_julia_mouse (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.fractal_explorer, 'KeyPressFcn', ';');
set(handles.button_zoom, 'Enable', 'off');
set(handles.txt_zoom_1, 'Visible', 'on');
ini_txt = get(handles.txt_zoom_1, 'String');
set(handles.txt_zoom_1, 'String', sprintf('Click mouse to compute current Julia\nSet; Press any key to cancel.'));
set(handles.preview_axis, 'Visible', 'on');
set(handles.txt_zoom_2, 'Visible', 'on');
axes(handles.preview_axis);
set(handles.preview_axis, 'DrawMode', 'fast');
xstep = (handles.xmax-handles.xmin)/handles.gridsize;
ystep = (handles.ymax-handles.ymin)/handles.gridsize;
xmin = handles.xmin;
ymin = handles.ymin;
dbt = 1;
pt = get(handles.fractal_explorer, 'CurrentPoint');
s_u = get(handles.fractal_explorer, 'Units');
set(handles.fractal_explorer, 'Units', 'Pixel');
pos = get(handles.fractal_explorer, 'Position');
pos(1) = pos(1)+20;
pos(2) = pos(2)+25;
set(handles.fractal_explorer, 'Units', s_u);
set(handles.fractal_explorer, 'CurrentCharacter', '?);
while strcmp(get(handles.fractal_explorer, 'CurrentCharacter'), '?) & (pt == get(handles.fractal_explorer, 'CurrentPoint'))
location = get(0, 'PointerLocation');
location(1) = location(1) - pos(1);
location(2) = location(2) - pos(2);
x = xmin + location(1)*xstep;
y = ymin + location(2)*ystep;
%disp([num2str(x) ' - ' num2str(y)]);
space2 = compute_julia_initial(-2, 2, -2, 2, x, y, 25, 150, 0);
if ~dbt
set(handles.preview_image, 'CData', space2);
else
handles.preview_image = image(space2);
set(handles.preview_image, 'EraseMode', 'none');
dbt = 0;
end
axis off;
drawnow;
end
set(handles.txt_zoom_1, 'String', ini_txt);
set(handles.txt_zoom_1, 'Visible', 'off');
set(handles.txt_zoom_2, 'Visible', 'off');
set(handles.preview_axis, 'Visible', 'off');
if isfield(handles, 'preview_image')
delete(handles.preview_image);
end
set(handles.button_zoom, 'Enable', 'on');
set(handles.fractal_explorer, 'KeyPressFcn', '');
set(handles.fractal_explorer, 'Name', 'CSE Fractals III');
if strcmp(get(handles.fractal_explorer, 'CurrentCharacter'), '?)
handles.xjul = x;
handles.yjul = y;
handles.xmin = -2;
handles.xmax = 2;
handles.ymin = -2;
handles.ymax = 2;
handles.itern = 70;
axes(handles.main_axis);
handles.space = compute_julia_initial(handles.xmin, handles.xmax, handles.ymin, handles.ymax, handles.xjul, handles.yjul, handles.itern, handles.gridsize, 1);
delete(handles.main_image);
handles.main_image = image(handles.space, 'EraseMode', 'none');
axis(handles.main_axis, 'off');
handles.mode = 2; % julia
handles = fillupdescription(handles);
end
% Update handles structure
guidata(hObject, handles);
% --------------------------------------------------------------------
function menu_julia_user_Callback(hObject, eventdata, handles)
% hObject handle to menu_julia_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('Julia Set:\n\nDefine Constant and iterations:\n\n');
tmp = {num2str(handles.xjul), num2str(handles.yjul), num2str(handles.itern)};
tmp = localdlg({[msg 'Constant Real:'], 'Constant Imaginary:', 'Iterations:'}, 'Julia Set', [1 10], tmp);
if isempty(tmp)
return;
end
handles.xmin = -2;
handles.xmax = 2;
handles.ymin = -2;
handles.ymax = 2;
handles.xjul = str2num(tmp{1});
handles.yjul = str2num(tmp{2});
handles.itern = str2num(tmp{3});
handles.mode = 2; % julia
handles = fillupdescription(handles);
handles.space = compute_julia_initial(handles.xmin, handles.xmax, handles.ymin, handles.ymax, handles.xjul, handles.yjul, handles.itern, handles.gridsize, 1);
handles.main_image = image(handles.space, 'EraseMode', 'none');
axis(handles.main_axis, 'off');
% Update handles structure
guidata(hObject, handles);
% --------------------------------------------------------------------
function menu_julia_Callback(hObject, eventdata, handles)
% hObject handle to menu_julia (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function menu_newton_head_Callback(hObject, eventdata, handles)
% hObject handle to menu_newton_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_newton_quad_Callback(hObject, eventdata, handles)
% hObject handle to menu_newton_quad (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles.xmin = -2;
handles.xmax = 2;
handles.ymin = -2;
handles.ymax = 2;
handles.itern = 70;
handles.mode = 3; % newton
handles.newton_equation = 'z^3 = -1';
handles.space = compute_newton(handles.xmin, handles.xmax, handles.ymin, handles.ymax, handles.itern, handles.gridsize, 1);
handles.main_image = image(handles.space);
axis(handles.main_axis, 'off');
set(handles.menu_julia_mouse, 'Enable', 'off'); % disable julia - makes no sense from newton.
handles = fillupdescription(handles);
% Update handles structure
guidata(hObject, handles);
% --------------------------------------------------------------------
function menu_head_complex_Callback(hObject, eventdata, handles)
% hObject handle to menu_head_complex (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in button_zoomout.
function button_zoomout_Callback(hObject, eventdata, handles)
% hObject handle to button_zoomout (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', 'off');
xsize = handles.xmax-handles.xmin;
ysize = handles.ymax-handles.ymin;
handles.txmin = handles.xmin-xsize/1.5;
handles.txmax = handles.xmax+xsize/1.5;
handles.tymin = handles.ymin-ysize/1.5;
handles.tymax = handles.ymax+ysize/1.5;
switch handles.mode
case -1 % logistic
space = compute_logistic(handles.txmin, handles.txmax, handles.tymin, handles.tymax, handles.itern/3, 150, 0);
case 1 % mandelbrot
space = compute_mandelbrot_real(handles.txmin, handles.txmax, handles.tymin, handles.tymax, handles.itern, 150, 0);
case 2 % julia
space = compute_julia(handles.txmin, handles.txmax, handles.tymin, handles.tymax, handles.xjul, handles.yjul, handles.itern, 150, 0);
case 3 % newton
space = compute_newton(handles.txmin, handles.txmax, handles.tymin, handles.tymax, handles.itern, 150, 0);
case 4 % user-newton
space = compute_newton_power(handles.txmin, handles.txmax, handles.tymin, handles.tymax, handles.itern, 150/handles.grain, handles.ctes, 0);
case 5 % barnsley
space = compute_barnsley(handles.txmin, handles.txmax, handles.tymin, handles.tymax, handles.xjul, handles.yjul, handles.itern, 15, 0);
case 6 % circu poly
if handles.arbitrary_mode == 1
space = compute_circumpoly(handles.txmin, handles.txmax, handles.tymin, handles.tymax, handles.xjul, handles.yjul, handles.itern/2, 150, 0);
else
space = compute_arbitrary(handles.equation, handles.txmin, handles.txmax, handles.tymin, handles.tymax, handles.xjul, handles.yjul, handles.itern, 30, 0);
end
otherwise
warning('CSE:Fractals:Render', 'Unknown Mode');
end
set(handles.txt_zoom_2, 'Visible', 'on');
set(handles.button_cancel, 'Visible', 'on');
set(handles.button_compute, 'Visible', 'on');
set(handles.preview_axis, 'Visible', 'on');
axes(handles.preview_axis);
if handles.mode > 0
handles.preview_image = image(space);
axis(handles.preview_axis, 'off');
else % we have an [x y] in space, not a complete table with space(x, y) = color
handles.preview_image = plot(space(:,1), space(:,2), 'b.', 'MarkerSize', 1);
axis(handles.preview_axis, [handles.txmin handles.txmax handles.tymin handles.tymax]);
set(handles.preview_axis, 'FontSize', 6);
end
guidata(hObject, handles);
% --- Executes on button press in button_zoom.
function button_zoom_Callback(hObject, eventdata, handles)
% hObject handle to button_zoom (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.txt_zoom_1, 'Visible', 'on');
set(handles.button_3D, 'Enable', 'off');
axes(handles.main_axis);
[x, y] = ginput(2);
xstep = (handles.xmax-handles.xmin)/handles.gridsize;
ystep = (handles.ymax-handles.ymin)/handles.gridsize;
if handles.mode == 4
if isfield(handles, 'grain')
if ~isempty(handles.grain)
xstep = xstep * handles.grain;
ystep = ystep * handles.grain;
end
end
end
if handles.mode > 0
if x(2) < x(1)
x1 = x(2);
x2 = x(1);
else
x1 = x(1);
x2 = x(2);
end
if y(2) < y(1)
y1 = y(1) - (x2-x1);
y2 = y(2);
else
y1 = y(1);
y2 = y(1) + (x2-x1);
end
handles.txmin = handles.xmin + x1 * xstep;
handles.txmax = handles.xmin + x2 * xstep;
handles.tymin = handles.ymin + y1 * ystep;
handles.tymax = handles.ymin + y2 * ystep;
%disp(sprintf('%0.25g-%0.25g:%0.25g-%0.25g',handles.txmin, handles.txmax, handles.tymin, handles.tymax));
else
handles.txmin = min(x);
handles.txmax = max(x);
handles.tymin = min(y);
handles.tymax = max(y);
end
switch handles.mode
case -1 % logistic
space = compute_logistic(handles.txmin, handles.txmax, handles.tymin, handles.tymax, handles.itern/3, 150, 0);
case 1 % mandelbrot
space = compute_mandelbrot_real(handles.txmin, handles.txmax, handles.tymin, handles.tymax, handles.itern, 150, 0);
case 2 % julia
space = compute_julia(handles.txmin, handles.txmax, handles.tymin, handles.tymax, handles.xjul, handles.yjul, handles.itern, 150, 0);
case 3 % newton
space = compute_newton(handles.txmin, handles.txmax, handles.tymin, handles.tymax, handles.itern, 150, 0);
case 4 % user newton
if handles.grain > 1
scl = 15;
else
scl = 150;
end
space = compute_newton_power(handles.txmin, handles.txmax, handles.tymin, handles.tymax, handles.itern, round(scl), handles.ctes, 0);
case 5 % barnsley
space = compute_barnsley(handles.txmin, handles.txmax, handles.tymin, handles.tymax, handles.xjul, handles.yjul, handles.itern, 150, 0);
case 6 % circu poly
if handles.arbitrary_mode == 1
space = compute_circumpoly(handles.txmin, handles.txmax, handles.tymin, handles.tymax, handles.xjul, handles.yjul, handles.itern/2, 150, 0);
else
space = compute_arbitrary(handles.equation, handles.txmin, handles.txmax, handles.tymin, handles.tymax, handles.xjul, handles.yjul, handles.itern, 30, 0);
end
otherwise
warning('CSE:Fractals:Render', 'Unknown Mode');
end
set(handles.txt_zoom_2, 'Visible', 'on');
set(handles.button_cancel, 'Visible', 'on');
set(handles.button_compute, 'Visible', 'on');
set(handles.preview_axis, 'Visible', 'on');
axes(handles.preview_axis);
if handles.mode > 0
handles.preview_image = image(space);
axis(handles.preview_axis, 'off');
else % we have an [x y] in space, not a complete table with space(x, y) = color
handles.preview_image = plot(space(:,1), space(:,2), 'b.', 'MarkerSize', 1);
axis(handles.preview_axis, [handles.txmin handles.txmax handles.tymin handles.tymax]);
set(handles.preview_axis, 'FontSize', 6);
end
guidata(hObject, handles);
% --------------------------------------------------------------------
function menu_head_real_Callback(hObject, eventdata, handles)
% hObject handle to menu_head_real (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -