function varargout = IFSfractal(varargin) % Построение геометрических фракталов с помощью систем итерируемых функций gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @IFSfractal_OpeningFcn, ... 'gui_OutputFcn', @IFSfractal_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(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 IFSfractal is made visible. function IFSfractal_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 IFSfractal (see VARARGIN) % Choose default command line output for IFSfractal handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes IFSfractal wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = IFSfractal_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; % Связь события CloseRequestFcn с подфункцией Close set(handles.output, 'CloseRequestFcn',{@Close,handles}); function Close(hObject,eventdata,handles)% Подфункция обработки события CloseRequestFcn окна приложения % Вывод модального диалогового окна с подтверждением закрытия q=questdlg('Закрыть приложение?','!!Информация!!','Да','Нет','Да'); % Проверка выбора пользователя if strcmp(q,'Да') % Пользователь подтвердил закрытие приложения, % удаляем окно приложения delete(handles.output); end % --- Executes on button press in btnPlot. function btnPlot_Callback(hObject, eventdata, handles) %матрица-система итерируемых функций ifs = dlmread(get(handles.EdtF,'String')); npts= str2double(get(handles.EdtB,'String')); [r,c] = size(ifs); if c<6 error('Matrix must have 6 columns'); end; % найти точки фрактала ... pt = [0;0]; A = [ ifs(1,1:2); ifs(1,3:4) ]; b = ifs(1,5:6)'; % ... повторяя первую функцию 50 раз for k=1:50 pt = A*pt+b; end; % затем мы вычисляем вес каждой функции detlist = zeros(1,r); for k=1:r detlist(k) = abs(ifs(k,1)*ifs(k,4) - ifs(k,2)*ifs(k,3)); end; % если все детерминанты - нуль, устанавливают detlist в весь 1's if all(detlist < 3*eps) detlist = ones(1,r); end; % найдем все нули в detlist... zlist = find(detlist < 3*eps); least = min(detlist(find(detlist>3*eps))); % ...и установливваем минимальные значения detlist(zlist) = (least/10)* ones(size(zlist)); % преобразуем detlist в вектор вероятности detlist = detlist/sum(detlist); % и вычислите выбранный вектор % вычисляя совокупные суммы selector = cumsum(detlist); % мы предвычисляем наши выборы rlist = rand(1,npts); choice = zeros(1,npts); for k=1:npts choice(k) = min(find(rlist(k) < selector)); end; pts = zeros(2,npts); % для хранения точек for k=1:npts p = choice(k); A = [ifs(p,1:2); ifs(p,3:4)]; b = ifs(p,5:6)'; pt = A*pt+b; pts(:,k) = pt; end; if get(handles.cbInd,'Value'), figure; end; % рисуем точки plot(pts(1,:),pts(2,:),'.'); str=strcat('IFS-фрактал: ',get(handles.EdtF,'String')); title(str); axis('off'); set(handles.btnClear, 'Enable', 'on'); function EdtF_Callback(hObject, eventdata, handles) % hObject handle to edit13 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of edit13 as text % str2double(get(hObject,'String')) returns contents of edit13 as a double % --- Executes during object creation, after setting all properties. function EdtF_CreateFcn(hObject, eventdata, handles) % hObject handle to edit13 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % --- Executes on button press in btnF. function btnF_Callback(hObject, eventdata, handles) % hObject handle to btnF (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) [flname, pname] = uigetfile('*.*','Выбор имени функции'); % получение имени и пути к файлу % Проверка, был ли открыт файл if flname ~= 0 % Образование полного имени файла RHSNAME = strrep(flname,'.m',''); end; set(handles.EdtF,'string',RHSNAME); % --- Executes on button press in btnClear. function btnClear_Callback(hObject, eventdata, handles) % hObject handle to btnClear (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) cla; % очистка осей % Кнопка Очистить должна стать недоступной после очистки осей set(hObject, 'Enable', 'off'); % Кнопка Построить должна стать доступной set(handles.btnPlot, 'Enable', 'on'); function EdtB_Callback(hObject, eventdata, handles) % hObject handle to EdtB (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of EdtB as text % str2double(get(hObject,'String')) returns contents of EdtB as a double % --- Executes during object creation, after setting all properties. function EdtB_CreateFcn(hObject, eventdata, handles) % hObject handle to EdtB (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % --- Executes on button press in cbInd. function cbInd_Callback(hObject, eventdata, handles) % hObject handle to cbInd (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: get(hObject,'Value') returns toggle state of cbInd