image thumbnail

Julia

by

 

Become a cyber explorer and use Julia to navigate the Fractal world!

julia(varargin)
%JULIA
% Top level GUI code for julia.m This drives all the callback functions.
% Non trivial ones are the functions which run the dynamic image bounding
% box facility and the Julia map update. Note in the latter there are some
% user definable parameters : maximum numbers of pixels per Argand diagram
% dimension (images with more pixels are split into patches and then joined
% after processing) ; and a binary flag which allows composite images (the
% patches) to be deleted or saved.
%
% LAST UPDATED by Andrew French 15/03/2011

function varargout = julia(varargin)

%Add Functions directory to path
addpath 'Functions' -begin

%Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
    'gui_Singleton',  gui_Singleton, ...
    'gui_OpeningFcn', @julia_OpeningFcn, ...
    'gui_OutputFcn',  @julia_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

%%

%Opening function
function julia_OpeningFcn(hObject, eventdata, handles, varargin)

%Turn off warnings
warning off;

%Get GUI information
handles = guidata(hObject);

%Set GUI window in middle of screen
set(handles.FIGUREjulia,'position',figcenter('FIGUREjulia'));

%Set GUI defaults
handles = julia_INI(handles);

%Update handles structure
guidata(hObject, handles);

%%

%Outputs from this function are returned to the command line.
function varargout = julia_OutputFcn(hObject, eventdata, handles)
varargout{1} = [];

%%

%Run this function when julia is closed
function varargout = CloseRequestFcn(hObject, eventdata, handles)
rmpath 'Functions'
closereq;

%%

%Window Button Down Function
function varargout = WindowButtonDownFcn(hObject, eventdata, handles)

%Get GUI data
handles = guidata(hObject);

%Get current coordinates of mouse pointer in axis units measured in [x y]
%from bottom hand corner of axis window
axes(handles.AXESjulia);
cp=get(gca,'currentpoint');
x = cp(1,1);
y = cp(1,2);

%Get axis limits
xlim=get(gca,'xlim');
ylim=get(gca,'ylim');

%Delete any previous bounding boxes
delete( handles.bbox_handle );
handles.bbox_handle = [];

%Change 'draw bounding box flag' from 0 to 1 if mouse click is within axis
%and update x1,y1 fields of handles.bbox structure
if (x <= xlim(2)) & (x >= xlim(1)) & ...
        (y <= ylim(2)) & (y >= ylim(1))
    handles.bbox_flag=1;
    handles.bbox.x1=x;
    handles.bbox.y1=y;
else
    handles.bbox_flag=0;
    handles.bbox.x1=NaN;
    handles.bbox.y1=NaN;
    handles.bbox.x2=NaN;
    handles.bbox.y2=NaN;
end

%Update handles structure
guidata(hObject, handles);

%%

%Window Button Up Function
function varargout = WindowButtonUpFcn(hObject, eventdata, handles)

%Get GUI data
handles = guidata(hObject);

%Determine boundaries of box and use this to set xc, yc and x width
%parameters.
x1=handles.bbox.x1;
x2=handles.bbox.x2;
y1=handles.bbox.y1;
y2=handles.bbox.y2;
xc=0.5*(x1+x2);
yc=0.5*(y1+y2);
xwidth = abs(x2-x1);

%Update GUI based upon coordinates of bounding box
set(handles.EDITxc,'string',num2str(xc));
set(handles.EDITyc,'string',num2str(yc));
set(handles.EDITxwidth,'string',num2str( xwidth ));

%Set 'draw bounding box flag' to be 0
handles.bbox_flag=0;

%Change Update button to amber
set(handles.PUSHupdate,'backgroundcolor',[1,0.502,0]);

%Update handles structure
guidata(hObject, handles);

%%

%Window Button Motion Function
function varargout = WindowButtonMotionFcn(hObject, eventdata, handles)

%Get GUI data
handles = guidata(hObject);

%Check initialization has run ... Sometimes this function is called before
%the handles array has been fully populated!
try
    %If 'draw bounding box flag' is 1 then determine current point within axis
    %and draw bounding box. Fixed aspect ratio of bounding box to equal the aspect ratio
    %of the julia map image.
    image_width_pixels = str2num(get(handles.EDITwidth,'string'));
    image_height_pixels = str2num(get(handles.EDITheight,'string'));
    if handles.bbox_flag==1
        
        %Point to julia axes and delete previous bounding box
        axes(handles.AXESjulia);
        delete(handles.bbox_handle);
        handles.bbox_handle = [];
        
        %Get axis limits
        xlim=get(gca,'xlim');
        ylim=get(gca,'ylim');
        
        %Determine top right hand corner of modified bounding box. Make
        %sure this doesn't extend beyond the axes.
        cp=get(gca,'currentpoint');
        x = cp(1,1);
        y = cp(1,2);
        
        %Check x extent first
        if x < xlim(1)
            x = xlim(1);
        elseif x > xlim(2)
            x = xlim(2);
        end
        
        %Force aspect to be correct based upon xwidth
        xwidth = x - handles.bbox.x1 ;
        ywidth = y - handles.bbox.y1 ;
        desired_aspect = image_height_pixels / image_width_pixels;
        y = handles.bbox.y1 + sign(ywidth)*abs(xwidth)*desired_aspect;
        
        %Check if y is now within axis. If not fix y by the
        %axis boundary and modify x
        if y < ylim(1)
            y = ylim(1);
            ywidth = y - handles.bbox.y1 ;
            x = handles.bbox.x1 + sign(xwidth)*abs(ywidth)/desired_aspect;
        elseif y > ylim(2)
            y = ylim(2);
            ywidth = y - handles.bbox.y1 ;
            x = handles.bbox.x1 + sign(xwidth)*abs(ywidth)/desired_aspect;
        end

        %Plot bounding box
        handles.bbox.x2 = x;
        handles.bbox.y2 = y;
        hold on;
        handles.bbox_handle = plot( [ handles.bbox.x1,...
            handles.bbox.x2,...
            handles.bbox.x2,...
            handles.bbox.x1,...
            handles.bbox.x1 ],...
            [ handles.bbox.y1,...
            handles.bbox.y1,...
            handles.bbox.y2,...
            handles.bbox.y2,...
            handles.bbox.y1 ],'k--' );
        hold off;
    end
    
    %Update handles structure
    guidata(hObject, handles);
end

%%

%Reset button callabck
function PUSHreset_Callback(hObject, eventdata, handles)

%Get GUI data
handles = guidata(hObject);

%Set GUI defaults
handles=julia_INI(handles);

%Change Update button to green
set(handles.PUSHupdate,'backgroundcolor',[0,1,0.251]);

%Update handles structure
guidata(hObject, handles);

%%

%Update button callback
function PUSHupdate_Callback(hObject, eventdata, handles)

%Get data from GUI
handles = guidata(hObject);
[width,height,xwidth,xc,yc,N,funcstr,...
    map_function,map_functions,map_creation_rule,map_creation_rules,C,NaN_colour,...
    cmap,cmaps,max_pixels,delete_composites]=get_gui_data(handles);

%Remove bounding box
delete( handles.bbox_handle );
handles.bbox_handle = [];

%Change Update button to green
set(handles.PUSHupdate,'backgroundcolor',[0,1,0.251]);

%Change handles.STOP flag to enable update to proceed
handles.STOP=0;
guidata(hObject,handles);

%Create 200 x 150 pixel julia map to determine normalization
isnorm=1;
julia_map=make_julia_map(200,150,max_pixels,xwidth,xc,yc,N,funcstr,...
    map_function,map_creation_rule,C,NaN_colour,cmap,[],[],isnorm);
if isempty(julia_map)
    set(handles.PUSHupdate,'backgroundcolor',[1,0.502,0]);
    return
end

%Determine maximum and minimum values
min_julia = min(min(real(julia_map)));
max_julia = max(max(real(julia_map)));

%Compute Julia map and save TIFF bitmap to current directory
isnorm=0;
julia_map=make_julia_map(width,height,max_pixels,xwidth,xc,yc,N,funcstr,...
    map_function,map_creation_rule,C,NaN_colour,cmap,min_julia,max_julia,isnorm);
if isempty(julia_map)
    set(handles.PUSHupdate,'backgroundcolor',[1,0.502,0]);
    return
end

%Split up width
num_x = ceil(width / max_pixels);

%Split up the height
num_y = ceil(height / max_pixels);

%Stitch the images back together
num=0;
A=[];
julia_image =[];
for nx = 1:num_x
    B = [];
    for ny = 1:num_y
        num = num + 1;
        A = imread(['julia_map_',num2str(num),'.png'],'png');
        B = [B; A];
    end
    julia_image = [julia_image, B];
end

%Write stitched bitmap and delete composite images, if option set
imwrite(julia_image,['julia_map.png'],'png');
if delete_composites==1
    for n=1:num
        delete(['julia_map_',num2str(n),'.png']);
    end
end

%Update GUI image with this new image
axes(handles.AXESjulia);
x=linspace(xc-xwidth/2,xc+xwidth/2,width);
y=linspace(yc-0.5*height*xwidth/width,yc+0.5*height*xwidth/width,height);
image(x,y,julia_image);
axis equal;
axis tight;
axis off;

%Change Update button to green
set(handles.PUSHupdate,'backgroundcolor',[0,1,0.251]);

%Update handles structure
guidata(hObject, handles);

%%

%z convergence radius
function EDITc_Callback(hObject, eventdata, handles)

%Get GUI data
handles = guidata(hObject);

%Change Update button to amber
set(handles.PUSHupdate,'backgroundcolor',[1,0.502,0]);

%Update handles structure
guidata(hObject, handles);

%%

%Bitmap width in pixels
function EDITwidth_Callback(hObject, eventdata, handles)

%Get GUI data
handles = guidata(hObject);

%Change Update button to amber
set(handles.PUSHupdate,'backgroundcolor',[1,0.502,0]);

%Update handles structure
guidata(hObject, handles);

%%

%Bitmap height in pixels
function EDITheight_Callback(hObject, eventdata, handles)

%Get GUI data
handles = guidata(hObject);

%Change Update button to amber
set(handles.PUSHupdate,'backgroundcolor',[1,0.502,0]);

%Update handles structure
guidata(hObject, handles);

%%

%Argand diagram x width
function EDITxwidth_Callback(hObject, eventdata, handles)

%Get GUI data
handles = guidata(hObject);

%Change Update button to amber
set(handles.PUSHupdate,'backgroundcolor',[1,0.502,0]);

%Update handles structure
guidata(hObject, handles);

%%

%Argand diagram x centre
function EDITxc_Callback(hObject, eventdata, handles)

%Get GUI data
handles = guidata(hObject);

%Change Update button to amber
set(handles.PUSHupdate,'backgroundcolor',[1,0.502,0]);

%Update handles structure
guidata(hObject, handles);

%%

%Argand diagram y centre
function EDITyc_Callback(hObject, eventdata, handles)

%Get GUI data
handles = guidata(hObject);

%Change Update button to amber
set(handles.PUSHupdate,'backgroundcolor',[1,0.502,0]);

%Update handles structure
guidata(hObject, handles);

%%

%Iterations editbox
function EDITiter_Callback(hObject, eventdata, handles)

%Get GUI data
handles = guidata(hObject);

%Change Update button to amber
set(handles.PUSHupdate,'backgroundcolor',[1,0.502,0]);

%Update handles structure
guidata(hObject, handles);

%%

%Julia function editbox
function EDITjuliafunction_Callback(hObject, eventdata, handles)

%Get GUI data
handles = guidata(hObject);

%Change Update button to amber
set(handles.PUSHupdate,'backgroundcolor',[1,0.502,0]);

%Update handles structure
guidata(hObject, handles);

%%

%NaN colour editbox
function EDITnancolor_Callback(hObject, eventdata, handles)

%Get GUI data
handles = guidata(hObject);

%Change Update button to amber
set(handles.PUSHupdate,'backgroundcolor',[1,0.502,0]);

%Update handles structure
guidata(hObject, handles);

%%

%Julia map creation rule popupmenu
function POPUPMENUmapcreationrule_Callback(hObject, eventdata, handles)

%Get GUI data
handles = guidata(hObject);

%Change Update button to amber
set(handles.PUSHupdate,'backgroundcolor',[1,0.502,0]);

%If map creation rule is 'plot z' then de-activate convergence radius edit
%box. (i.e. grey it out so it can't be used and confuse the user!)
map_creation_rules = get(handles.POPUPMENUmapcreationrule, 'string');
map_creation_rule = map_creation_rules{ get(handles.POPUPMENUmapcreationrule, 'value') };
if strcmp( map_creation_rule, 'plot z' )
    set( handles.EDITc,'Enable','off' );
else
    set( handles.EDITc,'Enable','on' );
end

%Update handles structure
guidata(hObject, handles);

%%

%Julia map function popupmenu
function POPUPMENUmapfunction_Callback(hObject, eventdata, handles)

%Get GUI data
handles = guidata(hObject);

%Change Update button to amber
set(handles.PUSHupdate,'backgroundcolor',[1,0.502,0]);

%Update handles structure
guidata(hObject, handles);

%%

%Set colormap popupmenu
function POPUPMENUcolormap_Callback(hObject, eventdata, handles)

%Get GUI data
handles = guidata(hObject);

%Change Update button to amber
set(handles.PUSHupdate,'backgroundcolor',[1,0.502,0]);

%Update handles structure
guidata(hObject, handles);

%%

%Max pixels in julia map edit box
function EDITmaxpixels_Callback(hObject, eventdata, handles)

%Get GUI data
handles = guidata(hObject);

%Change Update button to amber
set(handles.PUSHupdate,'backgroundcolor',[1,0.502,0]);

%Update handles structure
guidata(hObject, handles);

%%

%Stop button
function PUSHstop_Callback(hObject, eventdata, handles)

%Get GUI data
handles = guidata(hObject);

%Change Update button to amber and return control to the GUI, terminating
%the current run. This is done from make_julia_map.m, which has a check of
%the status of handles.STOP
set(handles.PUSHupdate,'backgroundcolor',[1,0.502,0]);
handles.STOP=1;

%Update handles structure
guidata(hObject, handles);

%%

%Set delete composites checkbox
function CHECKBOXdeletecomposites_Callback(hObject, eventdata, handles)

%Get GUI data
handles = guidata(hObject);

%Change Update button to amber
set(handles.PUSHupdate,'backgroundcolor',[1,0.502,0]);

%Update handles structure
guidata(hObject, handles);

%%

%Load GUI settings pushbutton
function PUSHloadsettings_Callback(hObject, eventdata, handles)

%Get GUI data
handles = guidata(hObject);

%Change Update button to amber
set(handles.PUSHupdate,'backgroundcolor',[1,0.502,0]);

%Return path to valid .mat file obtained via Explorer navigation by user
%which contains julia setup information.
[filename, pathname, filterindex] = uigetfile('*.mat', 'Choose a .mat file containing julia GUI settings');

%Load .mat file and update handles array of GUI with information contained
%within the .mat file. If this doesn't work flag up an error dialogue box
try
    load( [pathname, '\', filename] );
    handles = set_gui_data( handles, width,height,xwidth,xc,yc,N,funcstr,...
        map_function,map_functions,map_creation_rule,map_creation_rules,C,NaN_colour,...
        cmap,cmaps,max_pixels,delete_composites );
catch
    errordlg('.mat file selected does not contain the correct inputs for julia.m','julia error!')
    return
end

%Update handles structure
guidata(hObject, handles);

%%

%Save GUI settings pushbutton
function PUSHsavesettings_Callback(hObject, eventdata, handles)

%Get GUI data
handles = guidata(hObject);
[width,height,xwidth,xc,yc,N,funcstr,...
    map_function,map_functions,map_creation_rule,map_creation_rules,C,NaN_colour,...
    cmap,cmaps,max_pixels,delete_composites]=get_gui_data(handles);

%Return path to valid .mat file obtained via Explorer navigation by user
%which will contains julia setup information.
[filename, pathname, filterindex] = uiputfile('*.mat', 'Save julia GUI settings in a .mat file');

%Save .mat file containing GUI settings
if ~isequal(filename,0) && ~isequal(pathname,0)
    save( [pathname,'\',filename], 'width', 'height', 'xwidth', 'xc', 'yc', 'N', 'funcstr',...
        'map_function', 'map_functions','map_creation_rule','map_creation_rules','C','NaN_colour',...
        'cmap','cmaps','max_pixels','delete_composites' );
end

%Update handles structure
guidata(hObject, handles);

%End of code.


Contact us