
% In this section you may modify the mesh in any way that does not
% alter the set of nodes.

    if (Steps(m)==0) && m.globalDynamicProps.doinit  % Initialisation code.
        % Put any code here that should only be performed at the start of
        % the simulation, for example, to set up initial morphogen values.
        
        % m.nodes is the set of vertex positions, an N by 3 array if there
        % are N vertices.  Row number K contains the X, Y, and Z
        % coordinates of the Kth vertex. To obtain a list of the X
        % coordinates of every vertex, write m.nodes(:,1).  The Y
        % coordinates are given by m.nodes(:,2) and the Z coordinates by
        % m.nodes(:,3).
        
        % Set up the growth factor
        gradient=(m.nodes(:,1)-min(m.nodes(:,1)))/(max(m.nodes(:,1))-min(m.nodes(:,1))); % normalised to [0...1]
        id_g_p=0.05 * gradient;
    end
    
    % Monitor growth by scattering discs that deform over time (c.f. inducing biological clones)
    if (5>realtime-dt) && (5<realtime+dt) % discs to be added at realtime==5
        m = leaf_makesecondlayer( m, ...  % This function adds discs that represent transformed cells.
            'mode', 'each', ...  % Make discs randomly scattered over the canvas.
            'relarea', 1/1600, ...
            'numcells',100,...%number of discs (that will become ellipses)
            'sides', 6, ...  % Each discs is approximated as a 6-sided regular polygon.
            'probpervx', 1, ... % induce discs with this probability 
            'colors', [0.5 0.5 0.5], ...  % Default colour is gray but
            'colorvariation',0.1,... % Each disc is a random colour
            'add', true );
    end

%     % If you want to define different phases according to the absolute
%     % time, create a morphogen for each phase and modulate 
%     % expressions using the morphogen
%     % like.  For example:
    if (realtime < 10)  % initialisation
        f_initialising = 1;
    else
        f_initialising = 0;
    end
    if (realtime >= 10) % growth 
        f_growth = 1;
    else
        f_growth = 0;
    end
    
    switch modelname
        case 'CASE_B'  % @@model MODEL1
            % @@PRN Polariser Regulatory Network
                % see above
            % @@GRN Gene Regulatory Network
                % see above
            % @@KRN Growth Regulatory Network
                % Every equation to be formatted should end with an at-at Eqn N comment.
            kapar_p = f_growth * 0.5*id_g_l;  % growth only when realtime >= 10 hours
            kaper_p = kapar_p;  % fully isotropic growth
            kbpar_p = kapar_p;  % the same on both sides of the canvas
            kbper_p = kaper_p;  %
            knor_p  = 0;  % no change in thickness
            
    end