Cellular Automata with multiple colours as cells.

8 visualizaciones (últimos 30 días)
Obi Carwood
Obi Carwood el 25 de Mayo de 2019
Comentada: Obi Carwood el 26 de Mayo de 2019
I need to create cellular automata for an RGB array in MATLAB. Has to be matlab. How can I make cellular rules that are different for a specific coloured cell?
I've attempted code where it takes multiple functions and applies that function to each cell in my array.
function [gameBoard] = myCellularAutomata(gameBoard)
[R, C, ~] = size(gameBoard);
for k = 1:1000 % iterations of game
tempGameBoard = zeros(size(gameBoard));
updatedCellColour = [];
for r = 1:R
for c = 1:C
[updatedCellColour] = applyRule1(gameBoard, [r c]);
if isempty(updatedCellColour)
[updatedCellColour] = applyRule2(gameBoard, [r c]);
if isempty(updatedCellColour)
% etc.
end
end
% all rules have been applied or we have found one rule that satisfies its conditions
if isempty(updatedCellColour)
tempGameBoard(r,c,:) = updatedCellColour; % or however you plan to do this
end
end
end
gameBoard = tempGameBoard;
end
end
(This is code that someone kindly helped me out with, but it unfortunately does not work, either that, or i dont understand it properly)
I expected to recieve cellular automata that applies to the entire array all at once.
(EDIT)
Attached is the image I want to use as my initial array. The plan is to initiate a random walk of red cells onto the grey cells. Over time I want to implement cellular automata rules to the red cells and the cells around it. For instance; if the red cell is next to at least one blue cell, it dies. If a red cell is surrounded by 8 other red cells it dies. I want this simulation to run and stop at my command. I am fully aware on how to run standard 2D cellular automata with a masked (logical) image, but to implement rules for an RGB array is very new to me.
Note: I have a very handy function that alows me to turn any image into a pixelated array that I like, the only problem is is the cellular automata and random walk input. I am very novice when it comes to the style of coding, but am a fast learner. I appreciate any and all feedback.
Thankyou
(EDIT)
I apologise, I don't know hwo to enlarge the image, but if you zoom in, you should get the idea.
  5 comentarios
Obi Carwood
Obi Carwood el 26 de Mayo de 2019
This question has updated info, and I hoped reposting a question would attract more help.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Desktop en Help Center y File Exchange.

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by