function varargout = Schnakenberg_GUI(varargin)
% SCHNAKENBERG_GUI MATLAB code for Schnakenberg_GUI.fig
%      SCHNAKENBERG_GUI, by itself, creates a new SCHNAKENBERG_GUI or raises the existing
%      singleton*.
%
%      H = SCHNAKENBERG_GUI returns the handle to a new SCHNAKENBERG_GUI or the handle to
%      the existing singleton*.
%
%      SCHNAKENBERG_GUI('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in SCHNAKENBERG_GUI.M with the given input arguments.
%
%      SCHNAKENBERG_GUI('Property','Value',...) creates a new SCHNAKENBERG_GUI or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before Schnakenberg_GUI_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to Schnakenberg_GUI_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 Schnakenberg_GUI

% Last Modified by GUIDE v2.5 25-Mar-2015 18:16:25

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @Schnakenberg_GUI_OpeningFcn, ...
                   'gui_OutputFcn',  @Schnakenberg_GUI_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 Schnakenberg_GUI is made visible.
function Schnakenberg_GUI_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 Schnakenberg_GUI (see VARARGIN)

% Choose default command line output for Schnakenberg_GUI


ah = axes('unit','normalized','position',[0 0 1 1]);        % kezdeti háttér kirajzoltatás
bg = imread('hatter.png');                                  % az openingFcn-ben létrehozott részek a program 
imagesc(bg);                                                % indulásával lefutnak - kezdeti kirajzoltatás
set(ah,'handlevisibility','off','visible','off')
uistack(ah, 'bottom');

global Xinit;                                               % globális változónak def.
global Yinit;
global t_end;
global mu;

Xinit = get(handles.Xinit,'Value');                         % get - kérjük a Xinit osztály Value értékét (érdemes kipróbálni a csak get(handles.Xinit) parancsot)
Yinit = get(handles.Yinit,'Value');
mu = get(handles.Mu,'Value');
t_end = get(handles.Tend,'Value');

rajzol(Xinit, Yinit, t_end, mu, handles);                   % meghívjuk a kirajzol függvényünket a 4 bekért értékkel, plusz handlessel


handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes Schnakenberg_GUI wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = Schnakenberg_GUI_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 pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global Xinit;
global Yinit;
global t_end;
global mu;

Xinit = get(handles.Xinit,'Value');
Yinit = get(handles.Yinit,'Value');
mu = get(handles.Mu,'Value');
t_end = get(handles.Tend,'Value');




rajzol(Xinit, Yinit, t_end, mu, handles);                   % gombnyomás (Számold!) parancs után újrarajzol az aktuális paraméterértékekkel










% --- Executes on button press in checkbox1.
function checkbox1_Callback(hObject, eventdata, handles)
% hObject    handle to checkbox1 (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 checkbox1


% --- Executes on slider movement.
function Xinit_Callback(hObject, eventdata, handles)
% hObject    handle to Xinit (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,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider
global Xinit;
global Yinit;
global t_end;
global mu;

Xinit = get(handles.Xinit,'Value');
Yinit = get(handles.Yinit,'Value');
mu = get(handles.Mu,'Value');
t_end = get(handles.Tend,'Value');
set(handles.text7,'String',num2str(get(handles.Xinit,'Value')));
% rajzol(Xinit, Yinit, t_end, mu, handles);                             %
% ha ezt beaktiválnánk, akkor az X csúszka mozgatásával automatikusan
% kirajzolna - veszélyes, ha komoly számítás kell, lefagyhat a gyors
% mozgatástól









% --- Executes during object creation, after setting all properties.
function Xinit_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Xinit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end


% --- Executes on slider movement.
function Yinit_Callback(hObject, eventdata, handles)
% hObject    handle to Yinit (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,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider
set(handles.text8,'String',num2str(get(handles.Yinit,'Value')));





% --- Executes during object creation, after setting all properties.
function Yinit_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Yinit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end


% --- Executes on slider movement.
function Tend_Callback(hObject, eventdata, handles)
% hObject    handle to Tend (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,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider
set(handles.text9,'String',num2str(get(handles.Tend,'Value')));

% --- Executes during object creation, after setting all properties.
function Tend_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Tend (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end




% --- Executes on slider movement.
function Mu_Callback(hObject, eventdata, handles)
% hObject    handle to Mu (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,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider
set(handles.text10,'String',num2str(get(handles.Mu,'Value')));


% --- Executes during object creation, after setting all properties.
function Mu_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Mu (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end

function rajzol(Xinit, Yinit, t_end, mu, handles)                   % maga a rajzol függvény - õ végzi a munka nehezét :)

egyenlet = @(t, xy) [1/8-xy(1)+xy(1)^2*xy(2); mu-xy(1)^2*xy(2)];    % szokásos egyenlet deklarálás

[t, xy]=ode45(egyenlet, [0, t_end], [Xinit; Yinit]);                % diffegyenletet kiszámol


pipalva = get(handles.checkbox1,'Value');                           % ha a checkbox ki van pipálva (visszatérõ érték 1), akkor hold on
if pipalva == 1
    hold(handles.axes1, 'on');
    hold(handles.axes2, 'on'); 
else
    hold(handles.axes1, 'off');                                     % különben hold off
    hold(handles.axes2, 'off');
end

r = rand;                                                           % random színgenerálás kirajzoltatáshoz
g = rand;                                                           % random r g b kód 
b = rand;
szin = [r g b];
r2 = rand;
g2 = rand;
b2 = rand;
szin2 = [r2 g2 b2];


plot(handles.axes1, xy(:,1), xy(:,2), 'Color', szin);               % x-y ábrázolása
%title('x és y');
plot(handles.axes2, t, xy(:,1), 'Color', szin);                     % t-x ábrázolása
hold on;                                                            % hold on, hogy ez a két plot mindig együtt kerüljön kirajzoltatásra
plot(handles.axes2, t, xy(:,2), 'Color', szin2);                    % t-y ábrázolása másik színnel
set(handles.text7,'String',num2str(get(handles.Xinit,'Value')));    % ez csak csúszka értékeinek a frissítése a szövegmezõn
set(handles.text8,'String',num2str(get(handles.Yinit,'Value')));
set(handles.text9,'String',num2str(get(handles.Tend,'Value')));
set(handles.text10,'String',num2str(get(handles.Mu,'Value')));





