jeudi 6 juin 2019

Mapping the spread of a pattern(fractalart)

Essentially I'm trying to create a fractal pattern that expands from a certain point in an array like the image provided Fractal Pattern. Now in order to do this I've created two files, a function file that determines which indices I should change and a main file that deals with changing those indice values to one(other features may need to be added hence the reason why I have two files).

Conditions for the fractal:

-the fractal spreads directly north,south,east and west from the staring element.

-Elements can only have one neighbour.

Now lets say I want to create a fractal pattern that is 60x60 and the starting values is at (30,30) For my function file I currently have:

    function Fout = fractalfunc(inputmatrix)
for row = 1:60
    for col = 1:60 %go through matrix element by element
        if inputmatrix(row,col) == 1
            if inputmatrix(row-1,col)==0 && inputmatrix(row-1,col-1)==0 && inputmatrix(row-1,col+1)==0 %Checks North, NorthWest and NorthEast elements
              %Not sure what code should go here, trying to store my Fout
              %values in a nx2 matrix which essentially contains the indices
              %elements from the input matrix that need to be changed to 1.                
            end   
            if inputmatrix(row,col+1)==0 && inputmatrix(row-1,col+1)==0 && inputmatrix(row+1,col+1)==0 %Checks East, NorthEast and SouthEast elements
              %Not sure what code should go here, trying to store my Fout
              %values in a nx2 matrix which essentially contains the indices
              %elements from the input matrix that need to be changed to 1.    

            end
            if inputmatrix(row+1,col)==0 && inputmatrix(row+1,col-1)==0 && inputmatrix(row+1,col+1)==0 %Checks South, SouthWest and SouthEast elements 
              %Not sure what code should go here, trying to store my Fout
              %values in a nx2 matrix which essentially contains the indices
              %elements from the input matrix that need to be changed to 1.    

            end
            if inputmatrix(row,col-1)==0 && inputmatrix(row-1,col-1)==0 && inputmatrix(row+1,col-1)==0 %Checks West, NorthWest and SouthWest elements 
              %Not sure what code should go here, trying to store my Fout
              %values in a nx2 matrix which essentially contains the indices
              %elements from the input matrix that need to be changed to 1.    
            end
        end
    end
end
end

My main file has:

dims = 60;
mat1 = zeros(dims,dims);
mat1(round(dims/2), round(dims/2)) = 1;
for m = 1:63 % Number of iterations through fractal
    changeindices = fractalfunc(mat1);



    for k = 1:length(changeindices)
        mat1(changeindices(k,1), changeindices(k,2)) = 1; % Change pixel to one

    end
    figure(2),colormap(jet(8)),image(mat1)
    pause(0.01) 
    %Show result (in the loop will look like animation)
end

Things that I'm struggling in:

-The output values from the user-defined function needs to be a nx2 spreadsheet where it is populated by the values from certain indices elements that satisfy the IF statements. Really not sure how to do this, like for example when all five of my IF statements are true at row = 30 and col =30 then Fout = [29 30; 30 31;31 30;30 29] and this repeats essentially creating a list.

-How should I restart my loop, for example after it reaches the first 1 at (30,30), it will update the new North, East, South, West components and then I want the if statements will be executed on those new elements cuasing the pattern to propagate.

Thanks in advance:) (I've post alot I know, really new to MATLAB any advice is appreciated)

Aucun commentaire:

Enregistrer un commentaire