Cellular Automata with multiple colours as cells.

조회 수: 6 (최근 30일)
Obi Carwood
Obi Carwood 2019년 5월 25일
댓글: Obi Carwood 2019년 5월 26일
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
Obi Carwood
Obi Carwood 2019년 5월 26일
This question has updated info, and I hoped reposting a question would attract more help.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Desktop에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by